各位大哥帮忙看下以下这种写法能实现事物配置吗,谢谢各位了,框架是struts2 hibernate spring ,部分代码如下
applicationContext.xml
<bean id="transactionManager" class=
"org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory"/>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>*Service</value>
</list>
</property>
<property name="interceptorNames">
<value>transactionInterceptor</value>
</property>
</bean>
包:com.xx.action.admin
包下的类:AboutAction.java下的方法想实现事务管理,方法如下
public String addToAbout(){
aboutService.add(about);
aboutService.add( about);
}
配置文件里的*Service跟类里的aboutService有联系吗?目前测试是没有实现事务管理,第2次增加同样的一个对象的时候,抛出异常,但是第一次增加的已经写进了数据库,是不是还要写注解啥的?@Transactional 什么的?
------解决方案--------------------
当然了;
事务管理有两种:
1.注解:在方法事务方法前加上@Transactional
2.xml配置:在xml中加上advice和aop配置。
------解决方案--------------------
你申明注解事务的配置了吗
<context:annotation-config />
------解决方案--------------------
发错了,
<tx:annotation-driven transaction-manager="transactionManager"/>
------解决方案--------------------
理论上是这样