我感觉好象不用每次都重新写一个service.<bean id="petStore"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="target"><ref local="businessInterfaceImpl"/></property>
<property name="transactionAttributes">
<props>
<prop key="insert">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>对于不同的bean ,你只需要改变相应的
<property name="target"><ref local="businessInterfaceImpl"/></property>
和需要进行事务处理的方法,而对于
<property name="transactionManager"><ref bean="transactionManager"/></property>
你完全可以通用呀!
----------------------
也许我没有明白你的意思!
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="target"><ref local="businessInterfaceImpl"/></property>
<property name="transactionAttributes">
<props>
<prop key="insert">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>对于不同的bean ,你只需要改变相应的
<property name="target"><ref local="businessInterfaceImpl"/></property>
和需要进行事务处理的方法,而对于
<property name="transactionManager"><ref bean="transactionManager"/></property>
你完全可以通用呀!
----------------------
也许我没有明白你的意思!
解决方案 »
- webservice调用服务段出错 请高手给出解答 谢谢
- HttpServletRequestWrapper过滤请求中的参数问题
- schema验证问题
- 神奇的问题,局部变量相互影响
- 求BEAN的使用方法
- 请教:jasperreport1.2.5很奇怪的报错
- 怎样运行ejb程序?
- jboss-3.0.7_jakarta-tomcat-4.1.24+mysql4.0.14 整合问题!
- 请问finder和select方法有什么区别?
- 怎么样学习J2EE ???
- (POI)excel中实现当单元格中数据一行放不下时自动换行,自己实现,不能用HSSFCellStyle.setWrapText(true)。实在不知道怎么实现了!
- 最近运气很霉,求各位兄弟的祝福!谢谢了!
<bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/><!--事务拦截增强-->
<bean id="txInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref local="transactionManager"></ref>
</property>
<property name="transactionAttributes">
<props>
<prop key="save*"> PROPAGATION_REQUIRED,-Exception</prop>
<prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly,-Exception</prop>
<prop key="detail*">PROPAGATION_REQUIRED,readOnly,-Exception</prop>
</props>
</property>
</bean><!--事务增强器,应用于所有名称匹配的类、方法-->
<bean id="regexpMethodPointcutAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice">
<ref bean="txInterceptor"/>
</property>
<property name="patterns">
<list>
<value>.*Dao.*</value>
</list>
</property>
</bean>
<property name="target">
<list>
<ref bean="business" />
<ref bean="business1" />
</list>
</property>这样在你的程序中需要一个service去得到这个DAO的list,再根据不同的业务返回不同的DAO但是这样的效率有点低
<bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/>
有什么用处,能不能给全的看看
http://www.jactiongroup.net/reference/html/aop.html#aop-autoproxy
1.指定一个DefaultAdvisorAutoProxyCreator的bean定义2.在相同或相关上下文中指定任何数目的Advisor。注意这些必须是Advisor, 而不仅仅是拦截器或其它通知。这是很必要的,因为必须有一个切入点来检查每个通知是否符合候选bean定义。其中第二点最重要,所以在Little_qd(四年)给的例子中将TransactionInterceptor这个拦截器包装到regexpMethodPointcutAdvisor这个Advisor里面去,当然这也可以是其他的Advisor只有这样才能实现自动代理.下面是根据spring包内提供的测试类改的一个例子public interface ITestBean {}
public class TestBean implements ITestBean{}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><!--
Shows common interceptor along with advisor.
-->
<beans> <description>
Matches all Advisors in the factory: we don't use a prefix
</description> <bean id="aapc"
class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator">
<!-- This common interceptor will be applied always,
before custom lockable advisor --> </bean>
<!--
Stateful mixin. Will apply to all objects
Note that singleton property is false.
-->
<bean id="lockableAdvisor"
class="org.springframework.aop.support.DefaultPointcutAdvisor"
singleton="false"
/>
<bean id="test1"
class="org.springframework.beans.TestBean">
</bean>
</beans>
public class Test {
public static void main(String[] args) throws Exception {
testCommonInterceptorAndAdvisor();
}
public static void testCommonInterceptorAndAdvisor() throws Exception {
BeanFactory bf = new ClassPathXmlApplicationContext("advisorAutoProxyCreatorWithCommonInterceptors.xml");
ITestBean test1 = (ITestBean)bf.getBean("test1");
System.out.println(AopUtils.isAopProxy(test1)); }
}
所以也可以考虑使用自动代理的另一种实现BeanNameAutoProxyCreator
<bean id="txBeanNameProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames"><value>*Dao</value></property>
<property name="interceptorNames">
<list>
<value>txInterceptor</value>
</list>
</property>
</bean>
<bean id="abstractService"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true" >
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="transactionAttributes">
<props>
<prop key="do*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,read-only</prop>
</props>
</property>
</bean>然后:<bean id="businessService" extends="abstractService" >
<property name="target"><ref local="businessServiceTarget"/></property>
</bean>