spring+hibernate+proxool+jta(jotm)

最近配置公司新项目的开发环境,由于个人感觉proxool的数据源比较好用,但是发现网上没有相关方面配置jta的配置代码

于是个人总结后,记录了以下配置方式

 

以下配置的各开源版本

spring version 2.5.8

hibernate version 3.2

proxool version 0.9.1

这三个的版本比较关键,如果有问题,可能会发生冲突,关于jotm的版本比较宽松,这里不作特定要求

 

applicationContext-core.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"
	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"
	default-autowire="byName">

	<!-- JDBC Properties -->
	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="location" value="classpath:com/*/resource/jdbc.properties" />
	</bean>

	<!-- JTA TransactionManager -->
	<bean id="jotmJta" class="org.springframework.transaction.jta.JotmFactoryBean" /> 
	<bean id="jtaTxManager"  class="org.springframework.transaction.jta.JtaTransactionManager">
		<property name="userTransaction" ref="jotmJta"/> 
	</bean>

	<!-- Hibernate SessionFactory -->
	<!-- V7 sessionFactory -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<!-- 
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation">   
			<value>/WEB-INF/hibernate.cfg.xml</value>   
		</property>
		-->
		<property name="jtaTransactionManager" ref="jotmJta" />
		<property name="mappingDirectoryLocations">
			<list>
				<value>classpath:/com/*/hbm/v7</value>
			</list>
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					${hibernate.dialect}
				</prop>
				<prop key="hibernate.show_sql">
					${hibernate.show_sql}
				</prop>
				<prop key="hibernate.cache.provider_class">
					${hibernate.cache.provider_class}
				</prop>
				<prop key="hibernate.connection.release_mode">
					${hibernate.connection.release_mode}
				</prop>
				<prop key="hibernate.autoReconnect">
					${hibernate.autoReconnect}
				</prop>
				<prop key="hibernate.bytecode.use_reflection_optimizer">
					${hibernate.bytecode.use_reflection_optimizer}
				</prop>
				<prop key="hibernate.connection.autocommit">
					${hibernate.connection.autocommit}
				</prop>
				<prop key="hibernate.proxool.xml">
					${hibernate.proxool.xml}
				</prop>   
				<prop key="hibernate.proxool.pool_alias">
					${hibernate.proxool.pool_alias}
				</prop>   
			</props>
		</property>
	</bean>
	
	<!-- V4 sessionFactory -->
	<bean id="sessionFactoryV4" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="mappingDirectoryLocations">
			<list>
				<value>classpath:/com/*/hbm/v4</value>
			</list>
		</property>
		<property name="jtaTransactionManager" ref="jotmJta" />
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					${hibernate.dialect}
				</prop>
				<prop key="hibernate.show_sql">
					${hibernate.show_sql}
				</prop>
				<prop key="hibernate.cache.provider_class">
					${hibernate.cache.provider_class}
				</prop>
				<prop key="hibernate.connection.release_mode">
					${hibernate.connection.release_mode}
				</prop>
				<prop key="hibernate.autoReconnect">
					${hibernate.autoReconnect}
				</prop>
				<prop key="hibernate.bytecode.use_reflection_optimizer">
					${hibernate.bytecode.use_reflection_optimizer}
				</prop>
				<prop key="hibernate.connection.autocommit">
					${hibernate.connection.autocommit}
				</prop>
				<prop key="hibernate.proxool.xml">
					${hibernate.proxool.xml.v4}
				</prop>   
				<prop key="hibernate.proxool.pool_alias">
					${hibernate.proxool.pool_alias.v4}
				</prop>   
			</props>
		</property>
	</bean>
	
	<!-- Transaction Annotation -->
	<tx:annotation-driven transaction-manager="jtaTxManager"/>
	
	<!-- Persistence Dao -->
	<!-- V7 -->
	<bean id="v7Dao" class="com.*.dao.V7DaoImpl"></bean>
	
	<!-- V4 -->
	<bean id="v4Dao" class="com.*.dao.V4DaoImpl">
		<property name="sessionFactory" ref="sessionFactoryV4"></property>
	</bean>
</beans>

 

jdbc.properties配置:

#Hibernate Definition
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.show_sql=true
hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider
hibernate.connection.release_mode=auto
hibernate.autoReconnect=true
hibernate.bytecode.use_reflection_optimizer=true

hibernate.connection.autocommit=true
hibernate.connection.provider_class=org.hibernate.connection.ProxoolConnectionProvider
hibernate.proxool.xml=com/*/resource/proxool.xml
hibernate.proxool.pool_alias=V7
hibernate.proxool.xml.v4=com/*/resource/proxool.v4.xml
hibernate.proxool.pool_alias.v4=V4

 

proxool.xml(proxool.v4.xml同下)配置:

<?xml version="1.0" encoding="UTF-8"?>
<something-else-entirely>   
    <proxool>   
        <alias>V7</alias>
        <driver-url>jdbc:jtds:sqlserver://localhost:1433/test</driver-url>   
        <driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>   
        <driver-properties>
            <property name="user" value="sa"/>   
            <property name="password" value=""/>   
        </driver-properties>   
        <prototype-count>3</prototype-count>   
        <house-keeping-sleep-time>90000</house-keeping-sleep-time>
        <house-keeping-test-sql>select 1</house-keeping-test-sql>
        <minimum-connection-count>3</minimum-connection-count>
        <maximum-connection-count>30</maximum-connection-count>   
        <simultaneous-build-throttle>25</simultaneous-build-throttle>
        <statistics>10s,1m,1d</statistics>
        <statistics-log-level>Debug</statistics-log-level>
        <trace>false</trace>
        <verbose>true</verbose>
    </proxool>
</something-else-entirely>   

 

你可能感兴趣的:(spring,AOP,sql,Hibernate,bean)