1

我是一只新蜜蜂,正在使用微服务(Spring Boot,Spring Cloud),我试图在另一个微服务中使用资源文件。为此,我需要通过 ComponentScan 在另一个模块中扫描该模块。

就像我有一个管理模块一样,我需要在主模块中自动连接主资源。所以我使用:

@ComponentScan(basePackages = {"com.example.admin","com.example.main"}

我在AdminApplication文件中使用了它。现在它还在 Admin 中显示了我不想要的主模块的控制器。我谷歌它并申请:

  @ComponentScan(basePackages =
      {"com.example.admin","com.example.main"},
              excludeFilters = {@ComponentScan.Filter(type = ASSIGNABLE_TYPE,
                      value = {
                              UserController.class,
                              CustomerController.class,
                              SchoolController.class
                      })})

但它仍然在管理模块中显示这个主模块控制器。如何实际排除这个?请帮我。

4

2 回答 2

0

感谢您的建议。最后我得到了答案。

Swashbuckle 建立在 WebApi 的内置元数据层 - ApiExplorer 之上。如果您使用以下属性装饰控制器或操作:

[ApiExplorerSettings(IgnoreApi=true)]
public class MyController : ApiController

那么这最终会导致整个控制器或单个动作从 Swagger 输出中被忽略。

于 2018-09-28T10:30:41.153 回答
0

我猜,使用 JavaConfig (@Configuration) 和 @Profile 注释,您可以根据需要设置“进出”类的细微组合。但是你必须在你的主类上禁用@ComponentScan(不要使用@SpringBootApplication,也许,因为它嵌入了@ComponentScan)。

恕我直言,您应该模块化您的应用程序/服务,将公共资源构建为一个单独的 JAR,并将每个服务构建为一个不同的 Maven 模块,具体取决于它

于 2018-09-07T12:51:13.650 回答