问题
My question is how can i add a package to my list of component to scan @ComponentScan(basePackages = {"io.swagger", "com.company.project", like add it here }), but this package is in another module in my project,
here is the structure of my project :
springbootProject (maven project)/
module1(mavenProject, com.company.module1)
pom1.xml
module2(mavenProject, com.company.module2)
pom2.xml
pom.xml
in module 2 i have my main (@SpringbootAplication) where i want to @Autowired myRepository witch is in module 1
so how can i add the path
回答1:
Import ModuleB on ModuleA, and you'll be able to use it.
Project
|__ Module A (com.test.a)
|__ Module B (com.test.b)
In pom.xml
on ModuleA, add:
<dependency>
<groupId>com.test</groupId>
<artifactId>b</artifactId>
<version>1.0</version>
</dependency>
Then you should be able to add:
@ComponentScan(basePackages = {"com.test.b"})
来源:https://stackoverflow.com/questions/50043699/spring-boot-autowired-a-bean-from-another-module