views:

33

answers:

1

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?

+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
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
Well, yes, but that's the good of spring's flexibility. (btw, try not defining an "id", but a "name" instead)
Bozho
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