spring 配置的声明式事务不起作用是怎么回事
配置文件如下:<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEbeansPUBLIC"-//SPRING//DTDBEAN//E...
配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- dataSource config -->
<bean id ="dataSource" class ="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="url" value="jdbc:sqlserver://192.168.0.100:1433;DatabaseName=school" />
<property name="username" value="sa" />
<property name="password" value="sa"/>
</bean>
<!-- SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<!-- 中文検索解决方案 -->
<prop key="hibernate.query.factory_class">
org.hibernate.hql.ast.ASTQueryTranslatorFactory
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/ch/pojo/MCmpMan.hbm.xml</value>
</list>
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 配置拦截器 -->
<bean id="baseTxService"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean>
<!-- DAO -->
<bean id="mcmpmanDao" class="com.ch.dao.impl.MCmpManDAOIMPL">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<!-- Services -->
<bean id="mcmpmanService" parent="baseTxService">
<property name="target">
<bean class="com.ch.service.impl.MCmpManServiceIMPL">
<property name="mcmpmanDao">
<ref bean="mcmpmanDao"/>
</property>
</bean>
</property>
</bean>
<bean id="loginAction" class="com.ch.action.LoginAction" singleton="false">
<property name="mcmpmanService">
<ref bean="mcmpmanService"/>
</property>
</bean>
</beans>
故意在loginactin中报错
mcmpmanService.save(mCmpMansave1);
int i=Integer.parseInt("1as");
mcmpmanService.save(mCmpMansave2);
结果mCmpMansave1被提交到数据库了
,这个到底是那里的问题? ,没有rollback 展开
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- dataSource config -->
<bean id ="dataSource" class ="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="url" value="jdbc:sqlserver://192.168.0.100:1433;DatabaseName=school" />
<property name="username" value="sa" />
<property name="password" value="sa"/>
</bean>
<!-- SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<!-- 中文検索解决方案 -->
<prop key="hibernate.query.factory_class">
org.hibernate.hql.ast.ASTQueryTranslatorFactory
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/ch/pojo/MCmpMan.hbm.xml</value>
</list>
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 配置拦截器 -->
<bean id="baseTxService"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean>
<!-- DAO -->
<bean id="mcmpmanDao" class="com.ch.dao.impl.MCmpManDAOIMPL">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<!-- Services -->
<bean id="mcmpmanService" parent="baseTxService">
<property name="target">
<bean class="com.ch.service.impl.MCmpManServiceIMPL">
<property name="mcmpmanDao">
<ref bean="mcmpmanDao"/>
</property>
</bean>
</property>
</bean>
<bean id="loginAction" class="com.ch.action.LoginAction" singleton="false">
<property name="mcmpmanService">
<ref bean="mcmpmanService"/>
</property>
</bean>
</beans>
故意在loginactin中报错
mcmpmanService.save(mCmpMansave1);
int i=Integer.parseInt("1as");
mcmpmanService.save(mCmpMansave2);
结果mCmpMansave1被提交到数据库了
,这个到底是那里的问题? ,没有rollback 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询