View Full Version : using TransactionProxyFactoryBean with another Inteceptor
eleonhardo
Nov 18th, 2004, 07:21 AM
Hi,
I'm using the very convenient TransactionProxyFactoryBean. Is there any way to add another Interceptor ?
My bean definitions are:
<bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean"
abstract="true">
<property name="transactionManager"><ref bean="myTransactionManager"/></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,-RollbackException</prop>
<prop key="clean*">PROPAGATION_REQUIRED,-RollbackException</prop>
<prop key="delete*">PROPAGATION_REQUIRED,-RollbackException</prop>
...
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="RoleManager" parent="baseTransactionProxy" >
<property name="target" >
<bean class="xxx.model.managers.uam.RoleManagerImpl">
<property name="sessionFactory"><ref local="mySessionFactory"/></property>
</bean>
</property>
</bean>
Ben Alex
Nov 18th, 2004, 03:03 PM
The Acegi Security samples use both transactions and security interceptors. Here's two examples
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTran sactionManager">
<property name="dataSource"><ref local="dataSource"/></property>
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.Transa ctionInterceptor">
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="transactionAttributeSource">
<value>
sample.contact.ContactManager.create=PROPAGATION_R EQUIRED
sample.contact.ContactManager.getAllRecipients=PRO PAGATION_REQUIRED,readOnly
sample.contact.ContactManager.getAll=PROPAGATION_R EQUIRED,readOnly
sample.contact.ContactManager.getById=PROPAGATION_ REQUIRED,readOnly
sample.contact.ContactManager.delete=PROPAGATION_R EQUIRED
sample.contact.ContactManager.deletePermission=PRO PAGATION_REQUIRED
sample.contact.ContactManager.addPermission=PROPAG ATION_REQUIRED
</value>
</property>
</bean>
<bean id="contactManagerSecurity" class="net.sf.acegisecurity.intercept.method.aopalliance. MethodSecurityInterceptor">
<property name="authenticationManager"><ref bean="authenticationManager"/></property>
<property name="accessDecisionManager"><ref local="businessAccessDecisionManager"/></property>
<property name="afterInvocationManager"><ref local="afterInvocationManager"/></property>
<property name="objectDefinitionSource">
<value>
sample.contact.ContactManager.create=ROLE_USER
sample.contact.ContactManager.getAllRecipients=ROL E_USER
sample.contact.ContactManager.getAll=ROLE_USER,AFT ER_ACL_COLLECTION_READ
sample.contact.ContactManager.getById=ROLE_USER,AF TER_ACL_READ
sample.contact.ContactManager.delete=ACL_CONTACT_D ELETE
sample.contact.ContactManager.deletePermission=ACL _CONTACT_ADMIN
sample.contact.ContactManager.addPermission=ACL_CO NTACT_ADMIN
</value>
</property>
</bean>
<bean id="contactManager" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces"><value>sample.contact.ContactManager</value></property>
<property name="interceptorNames">
<list>
<idref local="transactionInterceptor"/>
<idref bean="contactManagerSecurity"/>
<idref local="contactManagerTarget"/>
</list>
</property>
</bean>
<bean id="contactManagerTarget" class="sample.contact.ContactManagerBackend">
<property name="contactDao"><ref local="contactDao"/></property>
<property name="basicAclExtendedDao"><ref bean="basicAclExtendedDao"/></property>
</bean>
plus
<bean id="domainManager" class="com.acegitech.dns.domain.DomainManagerImpl">
<property name="domainDao"><ref local="domainDao"/></property>
<property name="basicAclExtendedDao"><ref bean="basicAclExtendedDao"/></property>
</bean>
<bean id="domainManagerSecurity" class="net.sf.acegisecurity.intercept.method.aopalliance. MethodSecurityInterceptor">
<property name="authenticationManager"><ref bean="authenticationManager"/></property>
<property name="accessDecisionManager"><ref local="businessAccessDecisionManager"/></property>
<property name="afterInvocationManager"><ref local="afterInvocationManager"/></property>
<property name="objectDefinitionSource">
<value>
com.acegitech.dns.domain.DomainManager.createDomai n=ACL_DOMAIN_CREATE
com.acegitech.dns.domain.DomainManager.createResou rceRecord=ACL_RESOURCE_RECORD_CREATE
com.acegitech.dns.domain.DomainManager.deleteDomai n=ACL_DOMAIN_DELETE
com.acegitech.dns.domain.DomainManager.deleteResou rceRecord=ACL_RESOURCE_RECORD_DELETE
com.acegitech.dns.domain.DomainManager.findAllDoma insLike=ROLE_USER,AFTER_ACL_COLLECTION_READ
com.acegitech.dns.domain.DomainManager.findAllReso urceRecordsInDomain=ROLE_USER,AFTER_ACL_COLLECTION _READ
com.acegitech.dns.domain.DomainManager.obtainAdmin istrativePermission=ROLE_SUPERVISOR
com.acegitech.dns.domain.DomainManager.updateDomai n=ACL_DOMAIN_WRITE
com.acegitech.dns.domain.DomainManager.updateResou rceRecord=ACL_RESOURCE_RECORD_WRITE
</value>
</property>
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.Transa ctionInterceptor">
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="transactionAttributeSource">
<value>
com.acegitech.dns.domain.DomainManagerImpl.*=PROPA GATION_REQUIRED
com.acegitech.dns.domain.DomainManager.*=PROPAGATI ON_REQUIRED
</value>
</property>
</bean>
<bean id="autoproxy" class="org.springframework.aop.framework.autoproxy.Defaul tAdvisorAutoProxyCreator"/>
<bean id="methodSecurityAdvisor" class="net.sf.acegisecurity.intercept.method.aopalliance. MethodDefinitionSourceAdvisor" autowire="constructor"/>
<bean id="transactionAdvisor" class="org.springframework.transaction.interceptor.Transa ctionAttributeSourceAdvisor" autowire="constructor"/>
I personally prefer the DefaultAdvisorAutoProxyCreator approach, but you'll need to write an Advisor for your MethodInterceptor if one doesn't already exist.
irbouho
Nov 18th, 2004, 08:42 PM
TransactionProxyFactoryBean has two properties preInterceptors and postInterceptors that helps to apply more Interceptors.
Rod Johnson
Nov 22nd, 2004, 04:07 PM
The only limitation of TFP is that pre and post interceptors need to be singletons (shared instances). This is normally fine for "enterprise services" type aspects. Use ProxyFactoryBean or an auto proxy creator if you need to have per-proxy advice.
swillson
Dec 13th, 2004, 05:46 PM
I need to wrap an existing BO which uses TFB for transaction management
with an around advice. You mention that ProxyFactoryBean should
be used instead in more complex scenrios.
Is there an example of how to configure ProxyFactoryBean to do the hibernate transaction stuff?
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.