【发布时间】:2018-10-07 05:17:30
【问题描述】:
我正在尝试获得一个干净的 springboot maven 多模块项目。 我正在使用 springboot 2.0.1.RELEASE
我想要实现的和这个类似:SpringBootMultipleMavenModules
我遇到的问题是我希望能够在任何模块中注入我的依赖项。
例如在这个类中:DBSeeder.java 如下所示:
private HotelRepository hotelRepository;
public DbSeeder(HotelRepository hotelRepository){
this.hotelRepository = hotelRepository;
}
..
我想改用:
@Autowired
private HotelRepository hotelRepository;
Application 类如下所示:
@SpringBootApplication
@EnableJpaRepositories(basePackages = {"rc"})
@EntityScan(basePackages = {"rc"})
@ComponentScan(basePackages = {"rc"})
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
欢迎任何可以将我与解决方案联系起来的想法。
【问题讨论】:
-
在这里查看我的回复:stackoverflow.com/questions/50043699/…
-
@MagdKudama 不幸的是,这行不通,已经尝试过
-
什么是行不通的?
-
@MagdKudama Spring 会抱怨:rc.persistence.DbSeeder 中的 Field marriot 需要一个找不到的 'rc.domain.Hotel' 类型的 bean。
-
我什至没有在你的代码中看到
rc.domain.Hotel。它是否包含在组件扫描(或实体,取决于)中?您的 DbSeeder 类是 bean 吗?尝试将其标记为@Component
标签: spring-boot dependency-injection maven-3 multi-module