Announcement Announcement Module
No announcement yet.
How to run PostInterceptors with BeanNameAutoProxyCreator Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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:

    	<bean id="TemplateACLCheck" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="proxyTargetClass">
    		<!--inline transaction manager-->
    		<property name="transactionManager">
    			<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
    				<property name="sessionFactory"><ref local="sessionFactory"/></property>
    	    <property name="preInterceptors">
            	<ref local="ACLAdvisor"/>
    	    <property name="postInterceptors">
            	<ref local="ErrorLogAdvisor"/>
            	<ref local="AuditTrailAdvisor"/>        	
    		<property name="transactionAttributes">
    				<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>								
    	<bean id="AssignRightsManager"
    		<property name="target">
    			<bean class="" singleton="false"/> 
    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!