如何在包含的 JAR 中制作 Spring 的 @ComponentScan 搜索组件
How to make Spring's @ComponentScan search components in included JARs
我用 Spring 个组件制作了一个 jar 以包含在多个项目中 (core.jar)。
我创建了一个新的 Spring 项目,将 @ComponentScan 用于正确的包,但它不知道 jar 中的组件。
如何在包含的 JAR 中制作 Spring 的 @ComponentScan 搜索组件?
给它适当的包名称以在 JAR 中扫描。
@ComponentScan(basePackages = {"com.example.from.jar"})
我在 Spring boot 和 @ComponentScan 上遇到了类似的问题,这篇文档帮助我解决了这个问题:http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-structuring-your-code.html.
重点是我的 @SpringBootApplication
class 在 @ComponentScan
的 basePackages 之一的根包中。在我将其移动到子包后,Spring 能够识别所有 @ComponentScan
。
我用 Spring 个组件制作了一个 jar 以包含在多个项目中 (core.jar)。
我创建了一个新的 Spring 项目,将 @ComponentScan 用于正确的包,但它不知道 jar 中的组件。
如何在包含的 JAR 中制作 Spring 的 @ComponentScan 搜索组件?
给它适当的包名称以在 JAR 中扫描。
@ComponentScan(basePackages = {"com.example.from.jar"})
我在 Spring boot 和 @ComponentScan 上遇到了类似的问题,这篇文档帮助我解决了这个问题:http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-structuring-your-code.html.
重点是我的 @SpringBootApplication
class 在 @ComponentScan
的 basePackages 之一的根包中。在我将其移动到子包后,Spring 能够识别所有 @ComponentScan
。