您现在的位置是:首页 > 个人日记个人日记
spring-12-事务管理-xml配置
2019-02-03 18:57:46【个人日记】383人已围观
简介对事务的管理,XML配置
事务管理-xml配置
配置spring-config.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"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><!--扫描注解--><context:component-scan base-package="com.huangxin.order"></context:component-scan><!--AOP注解生效--><aop:aspectj-autoproxy></aop:aspectj-autoproxy><!--加载配置文件--><context:property-placeholder location="property/jdbc.properties"></context:property-placeholder><!--druid连接池--><bean id="dateSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="url" value="${jdbc.url}"></property><property name="username" value="${jdbc.username}"></property><property name="password" value="${jdbc.password}"></property></bean><!--SqlSessionFactory工厂交给spring--><bean id="sqlSessionFactory" name="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!--将数据源注入SqlSessionFactory--><property name="dataSource" ref="dateSource"></property><!--引入映射--><property name="mapperLocations" value="classpath:mapper/*.xml"></property></bean><!--让spring生成mapper接口的实现类--><!--多个mapper接口--><!--MapperScannerConfigurer将扫描所有包下的mapper--><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property><!--对哪些包下的类生成mapper代理类--><property name="basePackage" value="com.huangxin.order.mapper"></property></bean><!--事务管理--><bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dateSource"></property></bean><!--配置事务增强--><!--isolation事务隔离级别--><!--注意命名规范--><tx:advice id="txAdvice" transaction-manager="txManager"><tx:attributes><tx:method name="delete*" isolation="DEFAULT" propagation="REQUIRED"/><tx:method name="add*" isolation="DEFAULT" propagation="REQUIRED"/><tx:method name="insert*" isolation="DEFAULT" propagation="REQUIRED"/><tx:method name="update*" isolation="DEFAULT" propagation="REQUIRED"/></tx:attributes></tx:advice><!--增强事务--><aop:config><aop:advisor advice-ref="txAdvice" pointcut="execution(* com.huangxin.order.service.*.*(..))"/></aop:config></beans>
注意
这样使用集中配置,一旦配好不用再次配置,
但是配置比较麻烦.需要细心
Tags: JavaWeb
上一篇: spring-04-对象注入
下一篇: xml配置mybatis映射注意事项
相关文章
随机图文
评论区
2025-12-05 05:34:48
站长
没有登录功能是为了方便大家留言,但留言接口现在被恶意攻击,将关闭留言接口,如有疑问,请联系我的QQ 1538933906/同微信
