<?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/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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" default-autowire="byName"> <!-- 注意上面的default-autowire="byName",如果没有这个声明那么HibernateDaoSupport中 的sessionFactory不会被注入 --> <!-- 自动扫描组件,这里要把web下面的 controller去除,他们是在springMVC-mvc.xml中配置的, 如果不去除会影响事务管理的。--> <context:component-scan base-package="org.vo"> <context:exclude-filter type="regex" expression="org.controller.*"/> </context:component-scan> <bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean" /> <!-- JTA事务管理器 --> <bean id="myJtaManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="userTransaction" ref="jotm" /> </bean> <bean id="defaultSource" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown"> <property name="dataSource"> <bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown"> <property name="transactionManager" ref="jotm"></property> <property name="driverName" value="net.sourceforge.jtds.jdbc.Driver"></property> <property name="url" value="jdbc:jtds:sqlserver://127.0.0.1:1433/Interface;user=sa;password=123"></property> </bean> </property> <property name="user" value="sa"></property> <property name="password" value="123"></property> <property name="maxSize" value="1000"></property> <property name="minSize" value="2"></property> <property name="lifeTime" value="10"/> <property name="deadLockMaxWait" value="50"/> <property name="deadLockRetryWait" value="3"/> <property name="sleepTime" value="100"/> <!-- 自动重连 --> <property name="jdbcTestStmt" value="select 1" /> <property name="checkLevelObject" value="2"/> </bean> <bean id="theSecondSource" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown"> <property name="dataSource"> <bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown"> <property name="transactionManager" ref="jotm"></property> <property name="driverName" value="net.sourceforge.jtds.jdbc.Driver"></property> <property name="url" value="jdbc:jtds:sqlserver://127.0.0.1:1433/InterfaceApp;user=sa;password=123"></property> </bean> </property> <property name="user" value="sa"></property> <property name="password" value="123"></property> <property name="maxSize" value="10"></property> <property name="minSize" value="2"></property> <property name="lifeTime" value="10"/> <property name="deadLockMaxWait" value="50"/> <property name="deadLockRetryWait" value="3"/> <property name="sleepTime" value="100"/> <!-- 自动重连 --> <property name="jdbcTestStmt" value="select 1" /> <property name="checkLevelObject" value="2"/> </bean> <!--定义了Hibernate的SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="defaultSource"></property> <property name="jtaTransactionManager" ref="jotm" /> <!-- 配置Hibernate的参数 --> <property name="hibernateProperties"> <props> <prop key="hibernate.current_session_context_class"> jta </prop> <prop key="hibernate.transaction.factory_class"> org.hibernate.transaction.CMTTransactionFactory </prop> <!-- 指定数据库的方言 --> <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> <!-- 表示允许自动提交 --> <prop key="hibernate.connection.autocommit">true</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.connection.isolation">2</prop> <!-- JDBC执行批量更新语句的大小 清除缓存(定期清除缓存,减小压力 --> <prop key="hibernate.jdbc.batch_size">50</prop> <!-- <prop key="hibernate.cache.use_query_cache">true</prop>--> <prop key="hibernate.cache.use_second_level_cache">false</prop> <!-- <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>--> </props> </property> <property name="mappingLocations"> <list> <value>classpath*:org/vo/*.hbm.xml</value> <!-- <value>classpath*:org/voapp/*.hbm.xml</value>--> <!-- <value>classpath:org/website/vo/persale/*.hbm.xml</value> --> </list> </property> </bean> <!--定义了Hibernate的SessionFactorySecond --> <bean id="sessionFactorySecond" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="theSecondSource"></property> <property name="jtaTransactionManager" ref="jotm" /> <!-- 配置Hibernate的参数 --> <property name="hibernateProperties"> <props> <prop key="hibernate.current_session_context_class"> jta </prop> <prop key="hibernate.transaction.factory_class"> org.hibernate.transaction.CMTTransactionFactory </prop> <!-- 指定数据库的方言 --> <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> <!-- 表示允许自动提交 --> <prop key="hibernate.connection.autocommit">true</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.connection.isolation">2</prop> <!-- JDBC执行批量更新语句的大小 清除缓存(定期清除缓存,减小压力 --> <prop key="hibernate.jdbc.batch_size">50</prop> <!-- <prop key="hibernate.cache.use_query_cache">true</prop>--> <prop key="hibernate.cache.use_second_level_cache">false</prop> <!-- <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>--> </props> </property> <property name="mappingLocations"> <list> <!-- <value>classpath*:org/vo/*.hbm.xml</value>--> <value>classpath*:org/voapp/*.hbm.xml</value> <!-- <value>classpath:org/website/vo/persale/*.hbm.xml</value> --> </list> </property> </bean> <tx:advice id="txAdvice" transaction-manager="myJtaManager"> <tx:attributes> <tx:method name="check*" propagation="REQUIRED" read-only="true"/> <tx:method name="query*" propagation="REQUIRED" read-only="true"/> <tx:method name="get*" propagation="REQUIRED" read-only="true"/> <tx:method name="find*" propagation="REQUIRED" read-only="true"/> <tx:method name="is*" propagation="REQUIRED" read-only="true"/> <tx:method name="view*" propagation="REQUIRED" read-only="true"/> <tx:method name="save*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="del*" propagation="REQUIRED"/> <tx:method name="remove*" propagation="REQUIRED"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="basePointCuts" expression="execution(* org.service.*.*(..)) and execution(* org.serviceapp.*.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="basePointCuts" /> </aop:config> <bean id="baseDao" class="org.dao.impl.BaseDaoImpl" init-method="init" lazy-init="true"> <property name="sessionFactory"> <ref bean="sessionFactory"/> </property> </bean> <bean id="baseDaoSecond" class="org.dao.impl.BaseDaoImpl" init-method="init" lazy-init="true"> <property name="sessionFactory"> <ref bean="sessionFactorySecond"/> </property> </bean> <!-- 读取配置文件 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>/WEB-INF/classes/jdbc.properties</value> </property> </bean> --> <bean id="basicService" class="org.service.BasicService"> <property name="baseDao"> <ref bean="baseDao"/> </property> </bean> </beans>