spring中声明式事务的处理applicationContext.xml的配置

<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"  
    xmlns:tx="http://www.springframework.org/schema/tx"  
    xmlns:p="http://www.springframework.org/schema/p"  
    xmlns:aop="http://www.springframework.org/schema/aop"   
    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-3.0.xsd   
    http://www.springframework.org/schema/tx   
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd   
    http://www.springframework.org/schema/aop    
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">  
    <!-- 配置数据源-->
    <bean id="jdbcDataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="jdbcUrl">
<value>jdbc:oracle:thin:@127.0.0.1:1521:orcl</value>
</property>
<property name="user">
<value>bbs</value>
</property>
<property name="password">
<value>123</value>
</property>
</bean>
<!-- 配置mybatis的SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
      <property name="dataSource" ref="jdbcDataSource" />  
      <property name="configLocation" value="classpath:mybatis-config.xml"></property>  
   </bean>
   <!-- 配置dao层 -->
   <!--<bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
     <property name="mapperInterface" value="com.gxa.bj.dao.imp.UserMapper"></property>
     <property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
   </bean>-->
   <!-- mapper接口的扫描,必须扫描到接口,扫描的原则是:所有扫描进Spring的Mapper对象,它的命名规则: 首字母小写,
    后面的都是按照原有的接口名字定义。 比如UserMapper接口扫描到spring里,id名为userMapper -->

   <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
     <property name="basePackage" value="com.gxa.bj.dao.imp"></property>
     <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>

   </bean>


   <!-- 配置Service层 -->

   <!-- <bean id="userInfoService" class="com.gxa.bj.service.UserInfoService"> 

   <property name="userMapper" ref="userMapper"></property> 

   </bean> 

   <bean id="typeInfoService" class="com.gxa.bj.service.TypeInfoService"> 

    <property name="typeInfoMapper" ref="typeInfoMapper"></property>

    </bean> 

   <bean id="titleInfoService" class="com.gxa.bj.service.TitleInfoService"> 

   <property name="titleInfoMapper" ref="titleInfoMapper"></property>

   </bean> -->

   <!-- <context:component-scan base-package="com.gxa.bj.service"></context:component-scan> -->>


   <!-- 在spring中声明事务的配置 -->
   <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
   <property name="dataSource" ref="jdbcDataSource"></property>
   </bean>
   <!-- 事务增强的配置 -->
   <tx:advice id="txAdvice" transaction-manager="transactionManager">
 <tx:attributes>
  <tx:method name="get" read-only="true"/>
  <tx:method name="add*" rollback-for="Exception"/>
  <tx:method name="remove*" rollback-for="Exception"/>
 </tx:attributes>
   </tx:advice>
   <aop:config>
     <aop:pointcut expression="execution(public * com.gxa.bj.service.*.*(..))" id="serviceCut"/>
     <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceCut"/>

   </aop:config>

<!-- 扫描service层到spring容器里 -->
 <context:component-scan base-package="com.gxa.bj.service"/>

</beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值