`
tangxininjava
  • 浏览: 94830 次
  • 性别: Icon_minigender_1
  • 来自: 遂宁
社区版块
存档分类
最新评论

Spring配置ibatis

 
阅读更多
<?xml version="1.0" encoding="GBK"?>
<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">

	<!-- 加载数据库连接properties文件 -->
	<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="location">
			<value>classpath:jdbc.properties</value>
		</property>
	</bean>

	<!-- 配置数据源,proxool连接池 -->
	<bean id="dataSource"
		class="org.logicalcobwebs.proxool.ProxoolDataSource">
		<property name="driver">
			<value>${database.driver}</value>
		</property>
		<property name="driverUrl">
			<value>${database.url}</value>
		</property>
		<property name="user">
			<value>${database.username}</value>
		</property>
		<property name="password">
			<value>${database.password}</value>
		</property>
		<!-- 连接池别名 -->
		<property name="alias">
			<value>MyPool</value>
		</property>
		<property name="simultaneousBuildThrottle">
			<value>${database.connection.simultaneousBuildThrottle}</value>
		</property>
		<!-- 最少保持的空闲连接数 -->
		<property name="prototypeCount">
			<value>${database.connection.prototypeCount}</value>
		</property>
		<!-- 允许最小连接数 -->
		<property name="minimumConnectionCount">
			<value>${database.connection.minimumConnectionCount}</value>
		</property>
		<!-- 允许最大连接数,超过了这个连接,再有请求时,就排在队列中等候,最大的等待请求数由simultaneous-build-throttle决定;默认值为15 -->
		<property name="maximumConnectionCount">
			<value>${database.connection.maximumConnectionCount}</value>
		</property>
		<!-- 线程处于睡眠状态的最长时间,housekeeper检查各个连接的状态,判断是否需要销毁或者创建 -->
		<property name="houseKeepingSleepTime">
			<value>${database.connection.houseKeepingSleepTime}</value>
		</property>
		<!-- 如果housekeeper检测到某个线程的活动时间大于这个数值.它将会杀死这个线程(默认为5分钟) -->
		<property name="maximumActiveTime">
			<value>${database.connection.maximumActiveTime}</value>
		</property>
		<!-- 是否打印执行的SQL,true打印,false不打印 -->
		<property name="trace">
			<value>${database.connection.trace}</value>
		</property>
		<property name="verbose">
			<value>${database.connection.verbose}</value>
		</property>
		<property name="houseKeepingTestSql" value="SELECT SYSDATE FROM DUAL" />
	</bean>

	<bean id="sqlMapClient"
		class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
		<property name="configLocation">
			<value>classpath:ibatis/custom/SqlMapConfig.xml</value>
		</property>
		<property name="dataSource">
			<ref bean="dataSource" />
		</property>
	</bean>

	<!--根据sqlMapClien创建一个SqlMapClient模版类-->
	<bean id="sqlMapClientTemplate"
		class="org.springframework.orm.ibatis.SqlMapClientTemplate">
		<property name="sqlMapClient">
			<ref bean="sqlMapClient" />
		</property>
	</bean>

	<!-- 配置事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<!-- 配置事务的传播特性 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="select*" read-only="true" />
			<tx:method name="query*" read-only="true" />
			<tx:method name="get*" read-only="true" />
			<tx:method name="find*" read-only="true" />
			<tx:method name="load*" read-only="true" />
			<tx:method name="*" propagation="REQUIRED" />
		</tx:attributes>
	</tx:advice>

	<!-- 配制哪些类哪些方法使用事务 -->
	<aop:config>
		<aop:pointcut id="allManagerMethod"
			expression="execution(* com.tempus.tmc.*.service.*.*.*(..))" />
		<aop:advisor advice-ref="txAdvice"
			pointcut-ref="allManagerMethod" />
	</aop:config>
</beans>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics