Spring Boot @Autowired来自另一个模块的bean [英] spring boot @Autowired a bean from another module

查看:776
本文介绍了Spring Boot @Autowired来自另一个模块的bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是如何将软件包添加到要扫描的组件列表中,@ComponentScan(basePackages = {"io.swagger","com.company.project",例如在此处添加}),但是此软件包是在我项目的另一个模块中,

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,

这是我的项目的结构:

springbootProject(Maven项目)/

springbootProject (maven project)/

  module1(mavenProject, com.company.module1)
       pom1.xml

  module2(mavenProject, com.company.module2)
       pom2.xml

pom.xml

在模块2中,我有我的主文件夹(@SpringbootAplication),我想在其中进行@Autowired myRepository巫婆在模块1中

in module 2 i have my main (@SpringbootAplication) where i want to @Autowired myRepository witch is in module 1

所以我怎么添加路径

推荐答案

在ModuleA上导入ModuleB,您将可以使用它.

Import ModuleB on ModuleA, and you'll be able to use it.

Project
|__ Module A (com.test.a)
|__ Module B (com.test.b)

在ModuleA的pom.xml中,添加:

In pom.xml on ModuleA, add:

<dependency>
  <groupId>com.test</groupId>
  <artifactId>b</artifactId>
  <version>1.0</version>
</dependency>

然后您应该可以添加:

@ComponentScan(basePackages = {"com.test.b"})

这篇关于Spring Boot @Autowired来自另一个模块的bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆