Question

I'm looking for some kind of "best practice" informations about Spring jar configuration. I have a web project (war) and I need connect some jar libraries - my jars which contains additional functions. These jars contains Spring services. But when I connect jar, the service class did not work, because Spring don't know about that. So I need to tell Spring about this by “package auto scan” configuration inside my jar.

The final solution must be war project (main functions) and some additional jars which contains other functions. When I add jar into war project, I don't want to change configuration in applicationContext.xml (in war). I want minimal dependency to war project. I was thinking, when if I place applicationContext.xml to META-INF folder in jar it will be auto loaded by Spring, but it is not.

Do you know how can i solve this? May be some kind of “after startup dynamic configuration” :-). thanx

Was it helpful?

Solution

If you are trying to load annotated beans from the jars into your war's Spring context, you can set up a component scan in the war's context xml file to scan the packages in the jars.

If you are trying to load beans defined in XML files from the jars, you can include them using something like this in your war's Spring context xml file:

<import resource="classpath:path/to/config/in/jar/beans-from-jar.xml"/>

You shouldn't need to have your jar know anything about your war this way. You just scan the annotated beans and/or import the config from the jar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top