问题
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