Announcement Announcement Module
Collapse
No announcement yet.
How to run PostInterceptors with BeanNameAutoProxyCreator Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to run PostInterceptors with BeanNameAutoProxyCreator

    Hi everybody, I am looking for your help,
    Now, in my project, I use AOP to provide the system level service: ACL check, system log and error log etc.
    Following is the design:
    an preInterceptor do the ACL check before any transaction start.
    an postInterceptor do the error log (implements ThrowsAdvice)
    another postInterceptor do system log (implements AfterReturningAdvice)

    using delartive transaction to manage the transaction.

    So I choose TransactionProxyFactoryBean. following is the code:

    Code:
    	<bean id="TemplateACLCheck" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="proxyTargetClass">
    			<value>true</value>
    		</property>
    		<!--inline transaction manager-->
    		<property name="transactionManager">
    			<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
    				<property name="sessionFactory"><ref local="sessionFactory"/></property>
    			</bean>
    		</property>
    	    <property name="preInterceptors">
        	  <list>
            	<ref local="ACLAdvisor"/>
    	      </list>
        	</property>
    	    <property name="postInterceptors">
        	  <list>
            	<ref local="ErrorLogAdvisor"/>
            	<ref local="AuditTrailAdvisor"/>        	
    	      </list>
        	</property>
    		<property name="transactionAttributes">
    			<props>
    				<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
    				<prop key="select*">PROPAGATION_REQUIRED,readOnly</prop>
    				<prop key="save*">PROPAGATION_REQUIRED</prop>
    				<prop key="update*">PROPAGATION_REQUIRED</prop>				
    				<prop key="delete*">PROPAGATION_REQUIRED</prop>								
    			</props>
    		</property>
    	</bean>
    
    	<bean id="AssignRightsManager"
    			parent="TemplateACLCheck">
    		<property name="target">
    			<bean class="sg.com.process.AssignRightsManager" singleton="false"/> 
    		</property>
    	</bean>
    And everytime I use the getBean() to get the bean instance, the system always return the same object. I check the source code and find TransactionProxyFactoryBean always treat the target bean in singleton mode. So I create another TransactionProxyFactoryBean(in my own package, use proxyFactory.getProxy() in getObject()) and use PrototypeTargetSource to replace the SingletonTargetSource, but some funny things happen, the result is every strange(for the bean I retrieve from BeanFactory, the hashCode is always different).

    Now I give up and anybody can show me some lights: how to use postInterceptors and preInterceptors with BeanNameAutoProxyCreator.

    Thanks very much!
Working...
X