It is the second time that I stumble across that issue and I haven't found a good solution yet. My problem is that I want to package a framework like JAR with a default Spring context and give the user of my JAR package the possibility to use this configuration (or even an ApplicationContext implementation) to add his own bean definitions (from another config file) and to use or overwrite definitions from the default context. Does anybody know a good way to do this?
views:
33answers:
1
+1
A:
The people using your jar will have to import your .xml
file in theirs, with something like this:
<import resource="classpath*:/META-INF/spring-yourframework-init.xml" />
(/META-INF/spring-yourframework-init.xml
is the path of your xml in your jar. This xml file is a regular spring configuration file)
Bozho
2010-01-08 13:29:11
That makes sense, but doesn't it throw an exception if someone redefines an already existing definition (I would rather want it to overwrite the existing one)?
Daff
2010-01-08 13:36:51
Well, yes, but that's the good of spring's flexibility. (btw, try not defining an "id", but a "name" instead)
Bozho
2010-01-08 14:04:14
Thanks again, with defining a name and importing the resources from the classpath the overriding of bean definitions works without a problem. So that's exactly what I wanted :)
Daff
2010-01-16 19:17:06