Announcement Announcement Module
Collapse
No announcement yet.
Overriding bean defs in a parent bean factory by a child. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

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

    Code:
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<!-- Contains configurations specific only to the web application. -->
    		<param-value>
    			classpath&#58;com/nazco/mwc/web/resources/applicationContext-jndi.xml,
    		</param-value>
    		<description>Location of Spring configuration file&#40;s&#41;</description>
    	</context-param>
    	<!-- Load a shared service-layer parent application context &#40;visible to web and ejb&#41;. -->
    	<context-param>
    		<param-name>locatorFactorySelector</param-name>
    		<param-value>classpath&#58;com/nazco/mwc/service/resources/beanRefContext.xml</param-value>
    	</context-param>
    	<context-param>
    		<param-name>parentContextKey</param-name>
    		<param-value>com.nazco.mwc.service</param-value>
    	</context-param>
    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
Working...
X