spring+ibatis 事物出来(搞了一天)

    惭愧,现在才知道解决方法,哎……

    如果要事物处理不能try catch,就不能自己处理了,否则事物不回滚,

<?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:p="http://www.springframework.org/schema/p"
       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-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
   
     <bean id="propertyConfigurer"
            class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:/database.xml</value>
            </list>
        </property>
    </bean>
  
    <import resource="/applicationContent-dao.xml"/>
    <import resource="/applicationContent-service.xml"/>
    <import resource="/applicationContent-action.xml"/>
     
 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
     
     <property name="driverClassName">
   <value>${jdbcDriverClassName}</value>
  </property>
  <property name="url">
   <value>${jdbcUrl}</value>
  </property>
  <property name="username">
   <value>${jdbcUserName}</value>
  </property>
  <property name="password">
   <value>${jdbcPassword}</value>
  </property>
 </bean>
  
 <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
  <property name="dataSource">
   <ref bean="dataSource"/>
  </property>
  <property name="configLocations">
   <value>/WEB-INF/classes/sqlMapConfig.xml</value>
  </property>
 </bean>
 
 
 
  <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource">
            <ref bean="dataSource"/>
        </property>
    </bean>

    <aop:config>
        <aop:pointcut id="jdbcDaoOperationSupervision"
                  expression="execution(* excel.dansport.service..*.*(..))" />
        <aop:advisor advice-ref="supervisionTxAdvice" pointcut-ref="jdbcDaoOperationSupervision" />
    </aop:config>

    <tx:advice id="supervisionTxAdvice" transaction-manager="txManager">
        <tx:attributes>
            <tx:method name="find*" read-only="true" />
            <tx:method name="load*" read-only="true"/>
            <tx:method name="get*" read-only="true"/>
            <tx:method name="*" read-only="false" propagation="REQUIRED"  rollback-for="RuntimeException"/>
        </tx:attributes>
    </tx:advice>
 
 
 
</beans>

 

posted @ 2012-07-09 21:16  淡泊名利  阅读(639)  评论(0)    收藏  举报