Is it possible to use spring XML configuration file for each jar file with additional information?

My main Spring XML configuration file indicates the following:

<context:component-scan base-package="com.application" />

Components detected during this scan may be in one of many jar files in my class path. I would like to have additional Spring XML configuration files in each jar file that provide more information about each individual service / component (maybe some properties and much more), but I do not want these things to be closely linked to my main configuration file applications.

Is there a way to do this, or am I out of luck?

Ideally, I would like to somehow auto-detect the existence of an XML file in a JAR file based on the name and / or location in the JAR file.

I know that some things like this can be done with META-INF, but this is far beyond my competence.

+4
source share
1 answer

Ideally, I would like to somehow auto-detect the existence of an XML file in a JAR file based on the name and / or location in the JAR file.

Yes, it is quite simple.

In the main Spring text file, add something like this:

 <import resource="classpath*:config.xml"/> 

Note the lookup syntax. This scans the root of the classpath looking for any resources with the name config.xml and imports them into your main context.

That way, your JARs can have config.xml in their root directory and this will happen. These config.xml files can, of course, do their own import, etc.

+6
source

Source: https://habr.com/ru/post/1389351/


All Articles