首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

spring+ibatis+struts事宜控制配置

2012-11-07 
spring+ibatis+struts事务控制配置?xml version1.0 encodingUTF-8? !--- Application context de

spring+ibatis+struts事务控制配置
<?xml version="1.0" encoding="UTF-8"?>

<!--
  - Application context definition for JPetStore's business layer.
  - Contains bean references to the transaction manager and to the DAOs in
  - dataAccessContext-local/jta.xml (see web.xml's "contextConfigLocation").
  -->
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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.0.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">


<!-- ========================= GENERAL DEFINITIONS ========================= -->

<!-- Configurer that replaces ${...} placeholders with values from properties files -->
<!-- (in this case, mail and JDBC related properties) -->
<!-- serviceBean -->
<bean id="changingService" ref="changingDAOImpl"> </property>
    <property name="contractDao" ref="contractDAOImpl"> </property>
    <property name="reportDao" ref="reportDAOImpl"> </property>
    <property name="projectDao" ref="projectDAOImpl"> </property>
    <property name="scientistDao" ref="scientistDAOImpl"> </property>
</bean>
<bean id="contractService" ref="changingDAOImpl"> </property>
    <property name="contractDao" ref="contractDAOImpl"> </property>
    <property name="reportDao" ref="reportDAOImpl"> </property>
    <property name="projectDao" ref="projectDAOImpl"> </property>
    <property name="scientistDao" ref="scientistDAOImpl"> </property>
</bean>
<bean id="projectService" ref="changingDAOImpl"> </property>
    <property name="contractDao" ref="contractDAOImpl"> </property>
    <property name="reportDao" ref="reportDAOImpl"> </property>
    <property name="projectDao" ref="projectDAOImpl"> </property>
    <property name="scientistDao" ref="scientistDAOImpl"> </property>
</bean>
<bean id="reportService" ref="changingDAOImpl"> </property>
    <property name="contractDao" ref="contractDAOImpl"> </property>
    <property name="reportDao" ref="reportDAOImpl"> </property>
    <property name="projectDao" ref="projectDAOImpl"> </property>
    <property name="scientistDao" ref="scientistDAOImpl"> </property>
</bean>
<bean id="scientistService" ref="changingDAOImpl"> </property>
    <property name="contractDao" ref="contractDAOImpl"> </property>
    <property name="reportDao" ref="reportDAOImpl"> </property>
    <property name="projectDao" ref="projectDAOImpl"> </property>
    <property name="scientistDao" ref="scientistDAOImpl"> </property>
  </bean>

<!-- 配置数据源 -->
<bean id="dataSource" destroy-method="close">
  <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/kyproject"/>
<property name="username" value="root"/>
<property name="password" value="1234"/>
</bean>

<!-- 管理ibatis的事务,加载sql-map-config.xml文件 -->
<bean id="sqlMapClient" >
  <value>
  classpath:cn\edu\ysu\dao\sqlmap\sql-map-config.xml
  </value>
</property>
<property name="dataSource" ref="dataSource"/>
</bean>

<bean id="transactionManager" ref="dataSource"> </property>
</bean>

<!-- daoBean -->
  <bean id="changingDAOImpl" ref="sqlMapClient"/>
</bean>
<bean id="contractDAOImpl" ref="sqlMapClient"/>
</bean>
<bean id="projectDAOImpl" ref="sqlMapClient"/>
</bean>
<bean id="reportDAOImpl" ref="sqlMapClient"/>
</bean>

<bean id="scientistDAOImpl" ref="sqlMapClient"/>
</bean>


<!-- 代理,事务管理器,定义事务 -->
<bean id="daoProxy" ref="transactionManager"> </property>
  <property name="target">
  <list>
    <ref local="scientistService"/>
    <ref local="changingService"/>
    <ref local="contractService"/>
    <ref local="projectService"/>
    <ref local="reportService"/>
  </list>
  </property>
  <property name="transactionAttributes" >
    <props>
      <prop key="create*">PROPAGATION_REQUIRED </prop>
      <prop key="update*">PROPAGATION_REQUIRED </prop>
      <prop key="remove*">PROPAGATION_REQUIRED </prop>
      <prop key="to*">PROPAGATION_REQUIRED </prop>
      <prop key="*">PROPAGATION_REQUIRED,readOnly </prop>
    </props>
  </property>
</bean>

<!-- 配置事务特性 -->
<!-- 
<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
-->
<!-- 配置哪些类的方法需要事务 -->
<!--
<aop:config>
<aop:pointcut id="allMethod" expression="execution(* cn.edu.ysu.spring.service.ServiceManagerImpl.getScientistService(..))"/>
<aop:aspect id="other" ref="">
  <aop:before pointcut-ref="allMethod" method="other"/>
</aop:aspect>
</aop:config>

-->

热点排行