简体   繁体   中英

Spring context loading and component scan

This seems like a basic query but want to know if component scan tag can load applicationcontext files in the jar file?

For example:

I have defined component scan for package : com.xyz which is inside a jar file and this jar file has applicationContext.xml defined for the jar file inside com.xyxspring package. Will this context file get loaded while scanning for the components?

Also , this applicationcontext has reference to another xml file inside the same jar. Will dat also be loaded along with the applicationContext file.

Component scan only look for class files having the Spring annotation.

If you want to load Spring config files then you have to specify their path in your mail spring context configuration.

Instead of doing a component-scan in com.xyz , try importing the applicationContext.xml of that jar by placing this in your own spring context:

<import  resource="classpath:com/x/y/x/spring/applicationContext.xml"/>

I presume, this context file will define the beans of the com.xyz package. Spring will recursively load all context files referenced by this imported file as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM