如何使用自动装配和包装作为一个罐子 [英] How to use autowiring and package as a jar
问题描述
我正在尝试构建一个核心服务jar,我正在使用@ Component,@ Service和@Autowired注释来自动装配bean。
我打包成一个简单的罐子。
如何使用此jar的bean在另一个使用core-services jar作为pom依赖项的spring-boot应用程序中进行自动装配?
I am trying to build a core-services jar, where I am making use of @Component, @Service and @Autowired annotations to autowire beans. I am packaging as a simple jar. How do I use the beans of this jar to autowire in another spring-boot application which uses core-services jar as a pom dependency?
推荐答案
将它们作为pom依赖项添加后,您可以对它们进行配置,以便它们可以通过@ComponentScan进行审理
Once you add them as your pom dependencies, you can configure them so that they will get court to your @ComponentScan
所以在你的最终申请中
@SpringBootApplication
@ComponentScan(basePackages = { "com.dependency.first.package", "com.dependency.second.package"})
public class Application
{
使用上面的组件扫描,指向这些jar的根包,以便ComponentScan将检测您的依赖项中的所有组件和服务。
Using above component scan, point the root packages of those jars so that ComponentScan will detect all the components and services which are in your dependency jars.
这篇关于如何使用自动装配和包装作为一个罐子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!