kkkk如题!
废话不多说了,直接上配置,配置如下,各位看了便知!
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location"><value>classpath:jdbc.properties</value></property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="url"><value>${jdbc.url}</value></property>
<property name="driverClassName"><value>${jdbc.driver}</value></property>
<property name="username"><value>${jdbc.username}</value></property>
<property name="password"><value>${jdbc.password}</value></property>
<property name="defaultAutoCommit" value="false"></property>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor" >
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames"> <value>*Service</value></property>
<property name="interceptorNames"><value>transactionInterceptor</value></property>
</bean>
<bean id="sqlMapClientFactory" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation"><value>classpath:sqlMapConfig.xml</value></property>
<property name="dataSource" ref="dataSource"></property>
<property name="lobHandler">
<bean class="org.springframework.jdbc.support.lob.DefaultLobHandler"/>
</property>
</bean>
<bean id="sqlMapTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient" ref="sqlMapClientFactory" />
<property name="exceptionTranslator">
<bean class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator">
<property name="dataSource" ref="dataSource" />
</bean>
</property>
</bean>
</beans>
daoContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="employeeDao" class="mypackage.dao.impl.EmployeeDaoImpl">
<property name="sqlMapTemplate">
<ref bean="sqlMapTemplate" />
</property>
</bean>
</beans>
serviceContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="employeeService" class="mypackage.service.impl.EmployeeServiceImpl">
<property name="employeeDao"><ref bean="employeeDao" /></property>
</bean>
</beans>
在EmployeeServiceImpl中故意让程序抛出了exception,但是事务仍然提交了:-(
分享到:
相关推荐
SPRING与IBATIS整合采用保留IBATIS事务,可自己控制回滚!
很好的spring+ibatis事务的配置文档.
spring+ibatis声明式事务Demo源码
SPRING与IBATIS整合采用保留IBATIS事务,可自己控制回滚!
Spring与iBATIS的集成 iBATIS似乎已远离众说纷纭的OR框架之列,通常人们对非常流行的Hibernate情有独钟。但正如Spring A Developer's Notebook作者Bruce Tate 和Justin Gehtland所说的那样,与其他的OR框架相比...
spring+ibatis声明式事务Demo
本工程以“银行账号转账”为例子演示了如何处理Spring、Ibatis结合MySQL数据库使用时的事务操作 本工程编码方式:UTF-8 须执行的SQL语句: CREATE DATABASE `test`; USE `test`; CREATE TABLE `lm_bank_card` ( `...
spring ibatis 配置spring ibatis 配置spring ibatis 配置spring ibatis 配置
Struts2 Spring Hibernate IBatis Struts2 Spring Hibernate IBatisStruts2 Spring Hibernate IBatisStruts2 Spring Hibernate IBatis 只需要导入相应的jar包就行了 ,数据库是mysql :数据库名叫做mydatabase,表名...
有关Struts2+Spring+Hibernate和Struts2+Spring+Ibatis的整合实例demo 原创,完全基于eclipse开发
struts+spring+ibatis的Demo struts+spring+ibatis的Demo struts+spring+ibatis的Demo
是不是好东西你们去鉴定,SpringMVC + Spring + ibatis 可以配置多数据源,这个Demo 扩展性极强,就看你们自己如何发挥。
spring ibatis整合所需jar包
Spring对IBatis的整合 10.3 Spring对IBatis的支持 Spring对IBatis提供了完善的内建支持。使用Spring提供的IBatis辅助类,可以大大简化原有的IBatis访问代码。这些辅助类位于org.springframework.orm.ibatis包下,...
一个简单的struts+spring+ibatis示例的源码,在源码中包含一个简单的分布功能
struts+spring+ibatis做的一个增删改查例子
Spring+iBatis+JOTM实现JTA事务 spring ibatis jotm 分布 事务 多数据源
Spring+Ibatis技术:很好的架构文档
struts2+spring+ibatis+mysql AOP日志管理,异常捕获 tomcat6.0+jdk1.6