Announcement Announcement Module
Collapse
No announcement yet.
Alias name use within child context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Alias name use within child context

    I have an application that is being developed that utilizes several other components. Some using Spring and Hibernate. What I want to be able to do is create a top level context for the application that contains things such as the session factory and txn proxy template. For the components they will just have thier bean definitions etc. But I want the components to be able to use the session factory and txn template declared in the application context. My understanding is that I can do so by declaring aliases on the factory and template thru the use of the names attr. Those alias names would be how the components would refrence them. From what I read and infer from Java doc etc., this should work fine. But instead I am getting a NoSuchBeanDefinitionException when the reference to the alias is used.

    Here is my app context...
    Code:
        <bean id="ics.eBillDS" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            ...	
        </bean>
    
        <bean id="ics.propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            ....
        </bean>
    
        <bean id="ics.sessionFactory" name="ebill.sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
            ....
        </bean>
    
        <bean id="ics.transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
    	<property name="sessionFactory">
    		<ref local="ics.sessionFactory" />
    	</property>
        </bean>
    
        <bean id="ics.txProxyTemplate" name="ebill.txProxyTemplate"  class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    	<property name="transactionManager">
    		<ref local="ics.transactionManager" />
    	</property>
    	<property name="transactionAttributes">
    		<props>
    			<prop key="*">PROPAGATION_REQUIRED</prop>
    		</props>
    	</property>
    </bean>
    Here is my context for the component or child context
    Code:
    <beans>
         <bean id="ebill.testDelegate" parent="ebill.txProxyTemplate">
            <property name="target">
                <bean id="ebill.testDAOTarget" class="com.amfam.ics.common.service.test.TestDelegate" />
            </property>
        </bean>
    </beans>
    The alias on the txProxyTemplate matches the parent id on the testDelegate bean. Is this a case where you don't have a choice when using the parent attr?

    I know this should be simple, so I've got to be missing something here. If not, how are others doing this type of configuration of components.

  • #2
    When referencing a parent bean, I, usually, use its id.
    Also, consider marking your templates as abstract.
    HTH

    Comment

    Working...
    X