跨库事务处理 spring+hibernate+struts2+jta

来源:互联网 发布:天津办公软件培训 编辑:程序博客网 时间:2024/05/01 06:15
 <?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.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">

<bean id=
"dataSource"
class=
"org.apache.commons.dbcp.BasicDataSource">
<property name=
"driverClassName"
value=
"net.sourceforge.jtds.jdbc.Driver">
</property>
<property name=
"url"
value=
"jdbc:jtds:sqlserver://172.16.7.7:1433/NewsCenter">
</property>
<property name=
"username" value="vote"></property>
<property name=
"password" value="123456"></property>
<property name=
"maxActive">
<value>200</value>
</property>
<property name=
"maxIdle">
<value>70</value>
</property>
<property name=
"minIdle">
<value>60</value>
</property>
<property name=
"maxWait">
<value>2000</value>
</property>
<property name=
"initialSize">
<value>60</value>
</property>
<property name=
"removeAbandoned">
<value>true</value>
</property>
<property name=
"removeAbandonedTimeout">
<value>60</value>
</property>
<property name=
"logAbandoned">
<value>true</value>
</property>
</bean>

<bean id=
"newsDataSource"
class=
"org.apache.commons.dbcp.BasicDataSource">
<property name=
"driverClassName"
value=
"net.sourceforge.jtds.jdbc.Driver">
</property>
<property name=
"url"
value=
"jdbc:jtds:sqlserver://172.16.7.3:1433/NewsCenter">
</property>
<property name=
"username" value="cahpa"></property>
<property name=
"password" value="cahpa"></property>
<property name=
"maxActive">
<value>200</value>
</property>
<property name=
"maxIdle">
<value>70</value>
</property>
<property name=
"minIdle">
<value>60</value>
</property>
<property name=
"maxWait">
<value>2000</value>
</property>
<property name=
"initialSize">
<value>60</value>
</property>
<property name=
"removeAbandoned">
<value>true</value>
</property>
<property name=
"removeAbandonedTimeout">
<value>60</value>
</property>
<property name=
"logAbandoned">
<value>true</value>
</property>
</bean>

<bean id=
"sessionFactory"
class=
"org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name=
"dataSource">
<ref bean=
"dataSource" />
</property>
<property name=
"hibernateProperties">
<props>
<prop key=
"hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key=
"hibernate.hbm2ddl.auto">update</prop>
<prop key=
"hibernate.show_sql">true</prop>
</props>
</property>
<property name=
"mappingResources">
<list>
<value>cn/com/comment/pojos/Catalog.hbm.xml</value>
<value>cn/com/comment/pojos/Manager.hbm.xml</value>
<value>cn/com/comment/pojos/Role.hbm.xml</value>
<!--
<value>cn/com/comment/pojos/Channels.hbm.xml</value>
<value>cn/com/comment/pojos/Specials.hbm.xml</value>
<value>cn/com/comment/pojos/News.hbm.xml</value> -->
<value>cn/com/comment/pojos/Cmt.hbm.xml</value>
<value>cn/com/comment/pojos/CmtExt.hbm.xml</value>
<value>cn/com/comment/pojos/IpLock.hbm.xml</value>
</list>
</property>
</bean>

<bean id=
"newsSessionFactory"
class=
"org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name=
"dataSource">
<ref bean=
"newsDataSource" />
</property>
<property name=
"hibernateProperties">
<props>
<prop key=
"hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key=
"hibernate.hbm2ddl.auto">update</prop>
<prop key=
"hibernate.show_sql">true</prop>
</props>
</property>
<property name=
"mappingResources">
<list>
<!--
<value>cn/com/comment/pojos/Catalog.hbm.xml</value>
<value>cn/com/comment/pojos/Manager.hbm.xml</value>
<value>cn/com/comment/pojos/Role.hbm.xml</value>
<value>cn/com/comment/pojos/Cmt.hbm.xml</value>
<value>cn/com/comment/pojos/CmtExt.hbm.xml</value>
<value>cn/com/comment/pojos/IpLock.hbm.xml</value> -->
<value>cn/com/comment/pojos/Channels.hbm.xml</value>
<value>cn/com/comment/pojos/Specials.hbm.xml</value>
<value>cn/com/comment/pojos/News.hbm.xml</value>
</list>
</property>
</bean>

<bean id=
"jotm"
class=
"org.springframework.transaction.jta.JotmFactoryBean" />

<bean id=
"myTxManager"
class=
"org.springframework.transaction.jta.JtaTransactionManager">
<property name=
"userTransaction" ref="jotm" />
</bean>


<!-- 配置事务特性-->
<tx:advice id=
"txAdvice" transaction-manager="myTxManager">
<tx:attributes>
<tx:method name=
"save*" propagation="REQUIRED" />
<tx:method name=
"del*" propagation="REQUIRED" />
<tx:method name=
"update*" propagation="REQUIRED" />
<tx:method name=
"*" read-only="true" />
</tx:attributes>
</tx:advice>

<!-- 配置那些类的方法进行事务管理-->
<aop:config>
<aop:pointcut id=
"allManagerMethod"
expression=
"execution (* cn.com.comment.service.*.*(..))" />
<aop:advisor advice-ref=
"txAdvice"
pointcut-ref=
"allManagerMethod" />

</aop:config>

<bean id=
"catalogDao"
class=
"cn.com.comment.dao.catalog.impl.CatalogDAO">
<property name=
"sessionFactory" ref="sessionFactory" />
</bean>

<bean id=
"catalogService"
class=
"cn.com.comment.service.catalog.impl.CatalogService">
<property name=
"catalogDao" ref="catalogDao" />
</bean>

<bean id=
"managerDao"
class=
"cn.com.comment.dao.manager.impl.ManagerDAO">
<property name=
"sessionFactory" ref="sessionFactory" />
</bean>

<bean id=
"managerService"
class=
"cn.com.comment.service.manager.impl.ManagerService">
<property name=
"managerDao" ref="managerDao" />
</bean>


<bean id=
"roleDao"class="cn.com.comment.dao.role.impl.RoleDAO">
<property name=
"sessionFactory" ref="sessionFactory" />
</bean>

<bean id=
"roleService"
class=
"cn.com.comment.service.role.impl.RoleService">
<property name=
"roleDao" ref="roleDao" />
</bean>

<bean id=
"channelDao"
class=
"cn.com.comment.dao.channel.impl.ChannelDAO">
<property name=
"sessionFactory" ref="newsSessionFactory" />
</bean>

<bean id=
"channelService"
class=
"cn.com.comment.service.channel.impl.ChannelService">
<property name=
"channelDao" ref="channelDao" />
</bean>

<bean id=
"specialDao"
class=
"cn.com.comment.dao.special.impl.SpecialDAO">
<property name=
"sessionFactory" ref="newsSessionFactory" />
</bean>

<bean id=
"specialService"
class=
"cn.com.comment.service.special.impl.SpecialService">
<property name=
"specialDao" ref="specialDao" />
<property name=
"cmtDao" ref="cmtDao" />
</bean>

<bean id=
"newsDao"class="cn.com.comment.dao.news.impl.NewsDAO">
<property name=
"sessionFactory" ref="newsSessionFactory" />
</bean>

<bean id=
"newsService"
class=
"cn.com.comment.service.news.impl.NewsService">
<property name=
"newsDao" ref="newsDao" />
<property name=
"cmtDao" ref="cmtDao" />
</bean>

<bean id=
"cmtDao"class="cn.com.comment.dao.cmt.impl.CmtDAO">
<property name=
"sessionFactory" ref="sessionFactory" />
</bean>

<bean id=
"cmtService"
class=
"cn.com.comment.service.cmt.impl.CmtService">
<property name=
"cmtDao" ref="cmtDao" />
<property name=
"cmtExtService" ref="cmtExtService" />
<property name=
"newsDao" ref="newsDao" />
<property name=
"specialDao" ref="specialDao" />
</bean>

<bean id=
"cmtExtDao"
class=
"cn.com.comment.dao.cmtext.impl.CmtExtDAO">
<property name=
"sessionFactory" ref="sessionFactory" />
</bean>

<bean id=
"cmtExtService"
class=
"cn.com.comment.service.cmtext.impl.CmtExtService">
<property name=
"cmtExtDao" ref="cmtExtDao" />
</bean>

<bean id=
"ipDao"class="cn.com.comment.dao.ip.impl.IpDAO">
<property name=
"sessionFactory" ref="sessionFactory" />
</bean>

<bean id=
"ipService"
class=
"cn.com.comment.service.ip.impl.IpService">
<property name=
"ipDao" ref="ipDao" />
</bean>

<!--  <import resource=
"modelContext.xml"/>-->

</beans>
原创粉丝点击