我已经用 Feign Client 注释了 Spring Boot 应用程序
@SpringBootApplication
@EnableFeignClients({"com.ms.Foo1.api", "com.ms.Foo2.api",
"com.ms.Foo3.api", "com.ms.Foo4.api", "com.ms.Foo5.api", "com.ms.Foo6.api",
"com.ms.Foo7.api", "com.ms.Foo8.api", "com.ms.Foo9.api", "com.ms.Foo10.api"})
public class AnalyticsApplication extends SpringBootServletInitializer {
}
一切正常,因为我只是修改了基础包。它开始扫描 api 之外的包。
@SpringBootApplication
@EnableFeignClients({"com.ms.*.api"})
public class AnalyticsApplication extends SpringBootServletInitializer {
}
我期望 @EnableFeignClients({"com.ms.*.api"})
将仅扫描 api 内部的客户端,但它也会开始扫描 api 包外部。
我需要改变什么?或者我们可以在这里应用正则表达式而不是提及每个包吗?
最佳答案
您可以在 @ComponentScan 上使用正则表达式过滤器,如下所示:
@ComponentScan(basePackages = "com.ms",
includeFilters = @Filter(type = FilterType.REGEX, pattern="com.ms.*.api"))
public class AnalyticsApplication extends SpringBootServletInitializer {
}
但是@EnableFeignClients没有这个功能。你唯一能做的就是:
@EnableFeignClients(basePackages = "com.ms")
public class AnalyticsApplication extends SpringBootServletInitializer {
}
关于regex - @EnableFeignClients 包扫描 - spring boot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55534704/