spring boot @Autowired a bean from another module

随声附和 提交于 2020-01-13 01:26:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!