Announcement Announcement Module
Collapse
No announcement yet.
BeanPostProcessor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • BeanPostProcessor

    Hello.

    I'm trying to use a BeanPostProcessor to resolve a circular dependency issue. Unfortunately, my BeanPostProcessor isn't even being constructed when the ApplicationContext is loaded. Why could this possibly be?

    Here's the relevant section of my application-context.xml. Note that auditInterceptor normally would take a reference to dataCallback, but that introduces a circular dependency. So instead, I'd like auditInterceptorPostProcessor to inject a reference to dataCallback into auditInterceptor for me.

    Code:
    ...
        <bean id="dataCallback" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
            <property name="transactionManager">
                <ref local="transactionManager"/>
            </property>
            <property name="target">
                <ref local="lookupTarget"/>
            </property>
            <property name="transactionAttributes">
                <props>
                    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
                    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
                    <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
                    <prop key="store*">PROPAGATION_REQUIRED</prop>
                </props>
            </property>
        </bean>
    
        <!-- Transaction manager for Hibernate SessionFactory -->
        <bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
            <property name="sessionFactory">
                <ref local="sessionFactory"/>
            </property>
            <property name="entityInterceptor">
                <ref bean="auditInterceptor"/>
            </property>
        </bean>
        
        <bean id="auditInterceptor" class="com.company.commons.persist.audit.AuditInterceptor"/>
    
        <bean id="auditInterceptorPostProcessor" class="com.company.commons.persist.audit.AuditInterceptorPostProcessor" singleton="true">
            <property name="dataCallback">
                <ref bean="dataCallback"/>
            </property>
        </bean>
    ...
    Any ideas why my auditInteceptorPostProcessor isn't being instantiated? Also, neither postProcessBeforeInitialization nor postProcessAfterInitialization are being called.

    What am I doing wrong?
    -Alex

  • #2
    Re: BeanPostProcessor

    Originally posted by akw
    I'm trying to use a BeanPostProcessor to resolve a circular dependency issue. Unfortunately, my BeanPostProcessor isn't even being constructed when the ApplicationContext is loaded. Why could this possibly be?
    The circular dependency between HibernateTransactionManager and Hibernate Interceptors can be resolved by using the HibernateTransactionManager.setEntityInterceptorBe anName() method instead of the HibernateTransactionManager.setEntityInterceptor() method to set the Interceptor reference.

    Now my Interceptor can have a reference to the TransactionProxyFactoryBean without causing a circular reference problem when the ApplicationContext loads.

    -Alex

    Comment


    • #3
      Unfortunately, my BeanPostProcessor isn't even being constructed when the ApplicationContext is loaded.
      You should use an ApplicationContext instead of a BeanFactory so that BeanPostProcessor gets processed.

      Comment

      Working...
      X