How to make Spring's @ComponentScan search components in included JARs

前端 未结 2 1364
梦如初夏
梦如初夏 2020-12-05 11:27

I made a jar with Spring components to include in multiple projects (core.jar).

I created a new Spring project, have @ComponentScan to the correct package, but it i

相关标签:
2条回答
  • 2020-12-05 11:54

    Give it the appropriate package name to scan in the JAR.

    @ComponentScan(basePackages = {"com.example.from.jar"})
    
    0 讨论(0)
  • 2020-12-05 12:02

    I had a similar issue with Spring boot and @ComponentScan and this document helped me solving the issue: http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-structuring-your-code.html.

    The point was that my @SpringBootApplication class was in the root package of one of basePackages of @ComponentScan. After I moved it to a subpackage, Spring was able to recognize all @ComponentScans.

    0 讨论(0)
提交回复
热议问题