接Spring+Struts+ibatis下配置数据读写分离及事务(二)
6.配置spring-transaction.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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
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(数据源切换)-->
<bean id="dataSourceAdvice" class="com.ssi222.wilr.util.datasource.DataSourceAdvice"/>
<!--配置Service监控 -->
<aop:config>
<aop:advisor pointcut="execution(* com.ssi222.wilr.service..*Service.*(..))" advice-ref="dataSourceAdvice"/>
</aop:config>
<!--配置事务管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<!--配置事务控制特性-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!--对数据UPDATE操作支持事务-->
<tx:method name="add*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="insert*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="create*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="save*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="del*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="edit*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="modeify*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="update*" propagation="REQUIRED" rollback-for="Exception"/>
<!--对其他方法只支持只读事务-->
<tx:method name="*" propagation="SUPPORTS" read-only="true"/>
</tx:attributes>
</tx:advice>
<!--配置Service事务支持-->
<aop:config>
<aop:advisor pointcut="execution(* com.ssi222.wilr.service..*Service.*(..))" advice-ref="txAdvice"/>
</aop:config>
</beans>
7.配置bean对应的ibatis配置文件(只写了一个简单的测试)
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="System">
<typeAlias alias="Admin" type="com.ssi222.wilr.domain.bg.system.AdminInfo" />
<select id="loadLoginAdmin" resultClass="Admin" parameterClass="String">
<![CDATA[
SELECT * FROM tbl_admin WHERE account=#account#
]]>
</select>
</sqlMap>
8.配置ibatis配置文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<settings cacheModelsEnabled = "true"
enhancementEnabled = "true"
lazyLoadingEnabled = "true"
errorTracingEnabled = "true"
useStatementNamespaces = "true"
maxRequests = "512"
maxSessions = "128"
maxTransactions = "16"/>
<typeAlias alias="sql.date" type="java.sql.Date"/>
<typeAlias alias="sql.timestamp" type="java.sql.Timestamp"/>
<typeAlias alias="map" type="java.util.Map"/>
<typeAlias alias="list" type="java.util.List"/>
<typeAlias alias="hashmap" type="java.util.HashMap"/>
<typeAlias alias="hashset" type="java.util.HashSet"/>
<!--导入后台系统Ibatis配置-->
<sqlMap resource="config/ibatis/bg/ibatis-system.xml"/>
<!--导入前台系统Ibatis配置-->
</sqlMapConfig>
9.配置spring.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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
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">
<context:annotation-config />
<!-- 自动加载service presentation action-->
<context:component-scan base-package="com.ssi222.wilr.presentation.*" />
<context:component-scan base-package="com.ssi222.wilr.service.*" />
<context:component-scan base-package="com.ssi222.wilr.action.*" />
<!--导入数据源-->
<import resource="classpath:config/spring-datasource.xml"/>
<!--导入事务控制-->
<import resource="classpath:config/spring-transaction.xml"/>
<!--导入后台系统Service/Action配置-->
<import resource="classpath:config/spring/spring-bg.xml"/>
</beans>
分享到:
相关推荐
该项目是一款基于freeRTOS操作系统和STM32F103x微控制器的手机远程控制浴室温度系统设计源码,共包含1087个文件,包括580个C语言源文件、269个头文件、45个汇编源文件、36个数据文件、36个目标文件、35个编译规则文件、28个包含文件、27个文本文件、6个源文件、3个归档文件。此系统通过手机远程实现对浴室温度的有效控制,适用于智能浴室环境管理。
labview程序代码参考学习使用,希望对你有所帮助。
labview程序代码参考学习使用,希望对你有所帮助。
labview程序代码参考学习使用,希望对你有所帮助。
labview程序代码参考学习使用,希望对你有所帮助。