Spring 声明式事务配置的一种形式-Hibernate多事务

数据源:

jdbc.properties

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc\:mysql\://localhost\:3306/wgfmcg?autoReconnect\=true&useUnicode\=true&characterEncoding\=utf-8
jdbc.username=username
jdbc.password=password
jdbc.maximumConnectionCount=200
jdbc.houseKeepingSleepTime=15000
jdbc.houseKeepingTestSql=select CURRENT_DATE
jdbc.testBeforeUse=true
jdbc.alias=mysqlProxoolDataSource
jdbc.simultaneousBuildThrottle=1000
jdbc.trace=false


jdbc.initialPoolSize=10
jdbc.maxIdleTime=60
jdbc.acquireIncrement=5
jdbc.maxStatements=0
jdbc.idleConnectionTestPeriod=60
jdbc.acquireRetryAttempts=30
jdbc.breakAfterAcquireFailure=true
jdbc.testConnectionOnCheckout=false
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
pagemax=10
telephone=153,133,189
failsendnum=3
failsendtime=30
sendnumber=11100011111111
sessionTime=12
startupsms=true
serverip=202.102.126.40
exigenceinform=//BREW:0x01098087://KMS://MSG/
changeserverip=//BREW:0x01098087://KMS://SET/
personorientation=http://202.102.112.30/login.do?#jdbc.driver=oracle.jdbc.driver.OracleDriver
#jdbc.url=jdbc\:oracle\:thin\:@localhost\:1521\:ORCL
#jdbc.username=username
#jdbc.password=password
jdbc.useUnicode=true
jdbc.characterEncoding=UTF-8
<!--此bean告诉Spring去哪找数据库的配置信息,因为有此Bean才出现下面用${}标记来取变量的语句-->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="location" value="/WEB-INF/jdbc.properties" />
</bean>

<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource"
	lazy-init="false">
	<property name="driver">
		<value>${jdbc.driverClassName}</value>
	</property>
	<property name="driverUrl">
		<value>${jdbc.url}</value>
	</property>
	<property name="user">
		<value>${jdbc.username}</value>
	</property>
	<property name="password">
		<value>${jdbc.password}</value>
	</property>
	<property name="maximumConnectionCount">
		<value>${jdbc.maximumConnectionCount}</value>
	</property>
	<property name="houseKeepingSleepTime">
		<value>${jdbc.houseKeepingSleepTime}</value>
	</property>
	<property name="houseKeepingTestSql">
		<value>${jdbc.houseKeepingTestSql}</value>
	</property>
	<property name="testBeforeUse">
		<value>${jdbc.testBeforeUse}</value>
	</property>
	<property name="alias">
		<value>${jdbc.alias}</value>
	</property>
	<property name="simultaneousBuildThrottle">
		<value>${jdbc.simultaneousBuildThrottle}</value>
	</property>
	<property name="trace">
		<value>${jdbc.trace}</value>
	</property>
</bean>
<bean id="sessionFactory"
	class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
	<property name="dataSource" ref="dataSource" />
	<property name="mappingResources">
		<!-- Add by B.G. Dexin Zhang at Mar 5 2009  -->
         <value>
           <!-- Hibernate数据源-->
           <!-- com/jsict/fmcg/vo/TArea.hbm.xml -->
	</value>
</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					${hibernate.dialect}
				</prop>
				<prop key="hibernate.show_sql">false</prop>
				<prop key="hibernate.generate_statistics">true</prop>
				<prop key="hibernate.connection.autocommit">false</prop>
				<prop key="hibernate.connection.release_mode">after_statement</prop>
				<prop key="hibernate.cache.use_second_level_cache">false</prop>
				<prop key="hibernate.max_fetch_depth">15</prop>
			</props>
		</property>
		<property name="eventListeners">
			<map>
				<entry key="merge">
					<bean
						class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener" />
				</entry>
			</map>
		</property>
	</bean>

事务管理者:

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory" />
</bean>
   

被管理的对象:

<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
  <property name="transactionManager" ref="transactionManager" />
  <property name="transactionAttributeSource">
    <value>
     <!--com.jsict.fmcg.demo.TestAction.find*=PROPAGATION_REQUIRED,ISOLATION_DEFAULT,-ESPException,-RuntimeException-->
    </value>
  </property>
</bean>
<bean
		class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator">
		<property name="interceptorNames">
			<list>
				<value>transactionInterceptor</value>
			</list>
		</property>
	</bean>

	<bean
		class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
		<property name="transactionInterceptor" ref="transactionInterceptor" />
	</bean>

	<!-- Hibernate 3.0's JMX statistics service -->
	<!-- Implements the StatisticsServiceMBean management interface -->
	<bean name="broadengate:type=HibernateStatistics" class="org.hibernate.jmx.StatisticsService">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>

相关推荐