How to use autowiring and package as a jar

a 夏天 提交于 2019-12-25 04:16:09

问题


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?


回答1:


Once you add them as your pom dependencies, you can configure them so that they will get court to your @ComponentScan

So in your Final application

@SpringBootApplication
@ComponentScan(basePackages = { "com.dependency.first.package", "com.dependency.second.package"})
public class Application
{

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.



来源:https://stackoverflow.com/questions/52516110/how-to-use-autowiring-and-package-as-a-jar

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