@EnableFeignClients软件包扫描-Spring Boot

时间:2019-04-05 11:47:38

标签: regex spring-boot package netflix-feign

我已经用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 {
}

一切正常,因为我只是修改了base包。在api之外开始扫描程序包。

@SpringBootApplication
@EnableFeignClients({"com.ms.*.api"})
public class AnalyticsApplication extends SpringBootServletInitializer {
}

我期望@EnableFeignClients({"com.ms.*.api"})仅扫描api内的客户端,但也会开始扫描api包之外的内容。

我需要更改什么?还是我们可以在这里应用正则表达式,而不是提及每个软件包?

1 个答案:

答案 0 :(得分:0)

您可以在@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 {
}