Announcement Announcement Module
No announcement yet.
Overriding bean defs in a parent bean factory by a child. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Overriding bean defs in a parent bean factory by a child.

    My application contains a web layer, a service layer (DAOs, Hibernate, etc.), and an MDB EJB. In order to share the application context between the web layer and MDB, I used the org.springframework.context.access.ContextSingleto nBeanFactoryLocator.

    Just when I thought everything was working, it now seems that my bean definitions in the service layer that I expected to be overridden by definitions at the web layer are not. The web layer appears to be using the bean definitions defined for my service-layer units tests.

    That brings me to my question: Is it possible for my web app child application context to override bean definitions when the definitions are defined in the parent bean factory?

    In my situation I have an "applicationDataSource" defined in the service layer that is used for unit testing. But the web-layer has an "applicationDataSource" that uses the container pooling, etc. The service layer is loaded using the "beanRefContext.xml" file below:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//">
    	<!-- see JavaDoc for org.springframework.context.access.ContextSingletonBeanFactoryLocator -->
    	<bean id="com.nazco.mwc.service" class="">
    My web.xml attempts to override some of the bean definitions using the following in the web.xml:

    		<!-- Contains configurations specific only to the web application. -->
    		<description>Location of Spring configuration file&#40;s&#41;</description>
    	<!-- Load a shared service-layer parent application context &#40;visible to web and ejb&#41;. -->
    The file "applicationContext-persistence.xml" contains a unit-test bean "applicationDataSource", and the file "applicationContext-jndi.xml" contains the "applicationDataSource" for runtime in the web container. However the bean defined in the parent context doesn't seem to be overriden.

    Thanks in advance,
    Shannon Kendrick