Springboot多模块项目 [英] Springboot multimodule project
问题描述
我正在尝试获取一个干净的springboot maven多模块项目. 我正在使用springboot 2.0.1.RELEASE
我要实现的目标与此类似: SpringBootMultipleMavenModules >
我的问题是我希望能够将依赖项注入任何模块中.
例如在此类中: 我想改用: Application类如下: 欢迎将我与解决方案联系起来的任何想法. 看看您的代码,您不能 您需要在其中添加 说了这么多,对我来说,尝试注入 这样做,代码可以很好地编译. I'm trying to get a clean springboot maven multimodule project.
I'm using springboot 2.0.1.RELEASE What I want to achieve is similar to this: SpringBootMultipleMavenModules The problem I have is that I want to be able to inject my dependencies in any modules. For example in this class: DBSeeder.java looks as follow: I would like to use instead: The Application class look as follow: Any idea that could link me to the solution would be welcome. Looking at your code, you cannot You need to add Also, the project will never compile, as you're adding a non-existing module: https://github.com/IDCS1426/SpringBootMultipleMavenModules/blob/master/pom.xml#L14. You need to remove that :). Having said all of that, it's very weird to me the way you're trying to inject an By doing that, the code compiles just fine. 这篇关于Springboot多模块项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!private HotelRepository hotelRepository;
public DbSeeder(HotelRepository hotelRepository){
this.hotelRepository = hotelRepository;
}
..
@Autowired
private HotelRepository hotelRepository;
@SpringBootApplication
@EnableJpaRepositories(basePackages = {"rc"})
@EntityScan(basePackages = {"rc"})
@ComponentScan(basePackages = {"rc"})
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Autowire
一个Hotel
bean,因为它没有正确注册.@Component
以便将其注入 https://github.com/IDCS1426/SpringBootMultipleMavenModules/blob/master/pom.xml#L14 .您需要删除它:).Entity
的方式对我来说很奇怪,但这不是这个问题的一部分.private HotelRepository hotelRepository;
public DbSeeder(HotelRepository hotelRepository){
this.hotelRepository = hotelRepository;
}
..
@Autowired
private HotelRepository hotelRepository;
@SpringBootApplication
@EnableJpaRepositories(basePackages = {"rc"})
@EntityScan(basePackages = {"rc"})
@ComponentScan(basePackages = {"rc"})
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Autowire
a Hotel
bean, because it's not registered properly.@Component
there to be able to inject it in https://github.com/IDCS1426/SpringBootMultipleMavenModules/blob/master/persistence/src/main/java/rc/persistence/DbSeeder.java#L21Entity
like that, but that's not part of this question.