My main Spring Configuration XML file specifies something like this:
<context:component-scan base-package="com.application" />
The components found during this scan can be in one of many jar files on my classpath. I’d like to be able to have additional spring configuration XML files in each jar file that provide more information about each individual service/component (maybe some properties and whatnot), but I don’t want these things to be tightly coupled to my main application’s configuration file.
Is there a way to do this, or am I out of luck?
Ideally, I’d like to be able to somehow autodetect the existence of the XML file in the JAR file, based on name and/or location in the JAR file.
I know some things like this can be done with META-INF, but that’s far beyond my area of expertise.
Yes, this is pretty straightforward.
In your main Spring context file, add something like this:
Note the wildcard syntax. This will scan the root of the classpath looking for any resources called
config.xml, and will import them into your main context.So your JARs can each have a
config.xmlin their root directory, and it’ll just happen. Thoseconfig.xmlfiles can, of course, perform their own imports, and so on.