I have a dao jar file that contains all the domain objects and service classes. it has a config file dao-resource.xml with id=datasource.
I am using this jar file in another project which has its own app-context.xml, but i want to override the bean with id="datasource" in the jar file
how do i do this. I tried to add a bean with same id in app-context.xml and added both files to classpathxmlapplicat…. first dao-resource.xml then app-context.xml
but that did not seem to work.
how else can i override a bean
Having spring config files in jars makes things a bit harder to manage. If you have annotated your classes it would be easier.
But anyway, I’d suggest splitting the dao xml in two parts – your beans, and infrastructure-related beans (like the datasource). Then you can include only the ones you need in your app-context.xml.
Another way would be to use
primary="true"on your overriding bean. This would mean all injection points that need a bean of typeDataSource, would pick your primary bean. But that won’t work if you refer to your datasource in your dao xml.So in short – you can’t override a bean, so split your xml file and include only the parts you need.