`
qingwei201314
  • 浏览: 168653 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

jotm + spring

 
阅读更多

前段时间在网上看到一位仁兄用spring和jotm做应用,觉得配置文件可收藏,供以后使用时参考:

<?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/tx 
                           http://www.springframework.org/schema/tx/spring-tx-2.0.xsd 
                           http://www.springframework.org/schema/aop 
                           http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

 <!-- enables interpretation of the @Required annotation to ensure that dependency
  injection actually occures -->
 <bean
  class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" />

 <!-- enables interpretation of the @PersistenceUnit/@PersistenceContext
  annotations providing convenient access to EntityManagerFactory/EntityManager -->
 <bean
  class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

 <!-- first XA data source -->
 <bean id="bdbInnerDataSource" class="org.enhydra.jdbc.standard.StandardXADataSource">
  <property name="transactionManager" ref="jotm" />
  <property name="driverName" value="oracle.jdbc.driver.OracleDriver" />
  <property name="url" value="jdbc:oracle:thin:@HOST:PORT:SID" />
  <property name="user" value="USERNAME" />
  <property name="password" value="PASSWORD" />
 </bean>

 <!-- first XA data source pool -->
 <bean id="bdbDataSource" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource">
  <property name="transactionManager" ref="jotm" />
  <property name="dataSource" ref="bdbInnerDataSource" />
  <property name="user" value="USERNAME" />
  <property name="password" value="PASSWORD" />
  <property name="maxSize" value="4" />
 </bean>

 <!-- second XA data source -->
 <bean id="bpeInnerDataSource" class="org.enhydra.jdbc.standard.StandardXADataSource">
  <property name="transactionManager" ref="jotm" />
  <property name="driverName" value="oracle.jdbc.driver.OracleDriver" />
  <property name="url" value="jdbc:oracle:thin:@HOST:PORT:SID" />
  <property name="user" value="USERNAME" />
  <property name="password" value="PASSWORD" />
 </bean>

 <!-- second XA data source pool -->
 <bean id="bpeDataSource" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource">
  <property name="transactionManager" ref="jotm" />
  <property name="dataSource" ref="bpeInnerDataSource" />
  <property name="user" value="USERNAME" />
  <property name="password" value="PASSWORD" />
  <property name="maxSize" value="4" />
 </bean>

 <!-- required cos the standalone JOTM transaction manager is not autodetected
  by the JtaTransactionManager cos it requires a static accessor method -->
 <bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean" />

 <!-- supplying the JotmFactoryBean merely to the userTransaction property
  cos JtaTransactionManager autodetects that the object returned by the JotmFactoryBean
  implements both the UserTransaction and the TransactionManager interface -->
 <bean id="jtaTransactionManager"
  class="org.springframework.transaction.jta.JtaTransactionManager">
  <property name="userTransaction" ref="jotm" />
  <property name="allowCustomIsolationLevels" value="true" />
 </bean>

 <!-- settings previously specified in the persistence.xml JPA configuration
  file are now defined with the LocalContainerEntityManagerFactoryBean configuration -->
 <bean id="entityManagerFactory"
  class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  <!-- reference to the XA datasource -->
  <property name="dataSource" ref="bdbDataSource" />
  <!-- specify Hibernate as the the JPA provider -->
  <property name="jpaVendorAdapter">
   <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <property name="showSql" value="true" />
    <property name="generateDdl" value="false" />
    <property name="database" value="ORACLE" />
    <property name="databasePlatform" value="org.hibernate.dialect.OracleDialect" />
   </bean>
  </property>
  <!-- configure Hibernate to participate in JTA transactions using the JOTM
   transaction manager and specify further Hibernate specific configuration
   properties -->
  <property name="jpaPropertyMap">
   <map>
    <entry key="hibernate.transaction.manager_lookup_class"
     value="org.hibernate.transaction.JOTMTransactionManagerLookup" />
    <entry key="hibernate.transaction.flush_before_completion"
     value="true" />
    <entry key="hibernate.transaction.auto_close_session" value="true" />
    <entry key="hibernate.current_session_context_class" value="jta" />
    <entry key="hibernate.connection.release_mode" value="auto" />
   </map>
  </property>
  <!-- specify that the Hibernate JPA dialect should be used, probably not
   necessary since HibernateJpaVendorAdapter will most likely set this property -->
  <property name="jpaDialect">
   <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
  </property>
  <!-- custom implementation to enrich the PersistenceUnitInfo read from
   the persistence.xml JPA configuration file with the JTA datasource. specifying
   the JTA datasource directly in the Spring configuration file has the advantage
   that we can use a direct reference to the datasource instead of using a JNDI
   name as requied by the jta-data-source setting in the persistence.xml file -->
  <property name="persistenceUnitPostProcessors">
   <bean class="sample.JtaPersistenceUnitPostProcessor">
    <property name="jtaDataSource" ref="bdbDataSource" />
   </bean>
  </property>
 </bean>

 <!-- enables interpretation of the @Transactional annotation for declerative
  transaction managment using the specified JtaTransactionManager -->
 <tx:annotation-driven transaction-manager="jtaTransactionManager"
  proxy-target-class="false" />

 <!-- enables interpretation of the @Configurable annotation for domain object
  dependency injection -->
 <aop:spring-configured />
</beans>

 

2.经过整理后,我的spring配置文件如下(已测试通过):

<?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:context="http://www.springframework.org/schema/context"
 xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task"
 xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-3.0.xsd
   http://www.springframework.org/schema/jee
   http://www.springframework.org/schema/jee/spring-jee-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/aop
   http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
   http://www.springframework.org/schema/task
   http://www.springframework.org/schema/task/spring-task-3.0.xsd">

 <context:component-scan base-package="*" />
 <context:annotation-config />
 <aop:aspectj-autoproxy />

 <bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean" />
 <context:property-placeholder location="classpath:jdbc.properties" />

 <bean id="datasourcePool" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource">
  <property name="transactionManager" ref="jotm" />
  <property name="dataSource">
   <bean id="datasource" class="org.enhydra.jdbc.standard.StandardXADataSource">
    <property name="transactionManager" ref="jotm" />
    <property name="driverName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}" />
    <property name="user" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
   </bean>
  </property>
  <property name="user" value="${jdbc.username}" />
  <property name="password" value="${jdbc.password}" />
  <property name="maxSize" value="${jdbc.maxActive}" />
 </bean>

 <bean id="transactionManager"
  class="org.springframework.transaction.jta.JtaTransactionManager">
  <property name="userTransaction" ref="jotm" />
 </bean>
 <tx:annotation-driven transaction-manager="transactionManager"
  proxy-target-class="true" />

 <bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
  <property name="dataSource" ref="datasourcePool" />
  <property name="packagesToScan" value="com.kevin.entity" />
 </bean>
 <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
  <property name="sessionFactory" ref="sessionFactory" />
 </bean>

 <!-- 启动 Mina 供工作流用. -->
 <bean id="myemf"
  class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  <property name="dataSource" ref="datasourcePool" />
  <property name="persistenceUnitName" value="org.jbpm.mvnstruts2" />
  <property name="loadTimeWeaver">
   <bean
    class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
  </property>
 </bean>
 <bean
  class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

 <bean id="minaClient" class="com.kevin.workflow.MinaClient" />
 <bean id="taskClient" factory-bean="minaClient" factory-method="getTaskClient" />
 <bean id="ksession" class="com.kevin.workflow.Ksession"
  init-method="start" />
</beans>

 

分享到:
评论

相关推荐

    struts + spring + hibernate + velocity + ajax + jotm + acegi

    简介: struts + spring + hibernate + velocity + ajax + jotm + acegi ================================================================================================ 本资料共包含以下附件: 1161...

    spring+jotm+ibatis+mysql实现JTA分布式事务

    本项目“spring+jotm+ibatis+mysql实现JTA分布式事务”旨在利用这些技术来确保在分布式环境中的数据一致性。下面将详细介绍这个项目所涉及的知识点。 首先,Spring框架是Java开发中最常用的应用框架之一,它提供了...

    Spring+Jotm+Hibernate+Oracle+Junit 实现JTA分布式事务要求Demo工程

    2.Spring+Jotm整合实现JTA分布式事务,应用场景如转账等,同一事务内完成db1用户加100元、db2用户减100元。 3.Spring+Junit4单元测试,优点:不会破坏数据库现场,等等。 (特别注意:Spring3.0里不在提供对jotm的...

    spring 3.0.5 + jotm 实现的的spring mvc 的例子

    标题中的“spring 3.0.5 + jotm 实现的的spring mvc 的例子”表明这是一个关于使用Spring 3.0.5版本与JOTM(Java Open Transaction Manager)结合构建Spring MVC应用的示例项目。这个项目可能旨在演示如何在Spring ...

    Java分布式开发spring+jta+jotm

    "Java分布式开发spring+jta+jotm"的主题涵盖了Spring框架在分布式系统中的应用,特别是如何利用JTA和JOTM来处理跨资源的分布式事务。理解和掌握这些技术对于构建可扩展、健壮的Java应用至关重要。通过深入学习和实践...

    Spring+JOTM 分布式事务管理

    使用Spring+JOTM的分布式事务,可以确保这两个操作要么全部成功,要么全部回滚,避免出现部分完成的事务状态。 总结来说,Spring+JOTM的组合为开发者提供了一个强大的工具,用于处理复杂的分布式事务场景。通过声明...

    spring + JTA + JOTM实现分布式事务

    本教程将深入探讨如何使用Spring框架、Java Transaction API (JTA) 和 Java Open Transaction Manager (JOTM) 来实现这样的分布式事务管理。 首先,我们来了解一下JTA。JTA是Java平台的标准事务API,它允许应用程序...

    Spring+iBatis+JOTM实现JTA事务

    在集成Spring+iBatis+JOTM的环境中,Spring主要负责事务策略的配置和管理,iBatis则作为持久层框架,负责SQL的执行,而JOTM作为事务管理器,确保跨数据库的事务一致性。 1. **环境搭建** - 首先,确保安装了JDK ...

    spring+jotm 多数据源事务管理(二)hibernate

    本篇文章将聚焦于如何结合Spring和JOTM(Java Open Transaction Manager)来实现多数据源的事务管理,特别是针对使用Hibernate的情况。 JOTM是Java平台上的一个开放源代码事务管理器,它遵循JTA(Java Transaction ...

    多数据源 更新 spring jta java jotm

    本文将深入探讨如何使用Spring、Java Transaction API (JTA) 和 Java Object Transaction Manager (JOTM) 实现多数据源更新的解决方案。 首先,让我们理解什么是多数据源。在传统的单数据源环境中,应用程序通常...

    spring+jotm 多数据源事务管理(三)JNDI+Tomcat

    ### Spring + JOTM 多数据源事务管理详解(三):JNDI + Tomcat 在本篇文章中,我们将深入探讨如何利用Spring框架结合JOTM(Java Open Transaction Manager)来实现多数据源下的分布式事务管理。我们将通过具体实例...

    spring-hibernate-jotm 例子

    标题“spring-hibernate-jotm 例子”涉及的是一个整合Spring框架、Hibernate持久化框架以及JOTM(Java Open Transaction Manager)事务管理器的示例项目。这个项目旨在展示如何在Java应用程序中有效地管理和协调...

    spring JTA集成JOTM或Atomikos配置分布式事务(Tomcat应用服务器)

    总结来说,集成Spring、JTA、JOTM或Atomikos进行分布式事务处理,是提高系统扩展性和可靠性的重要手段。通过上述步骤,开发者能够在Tomcat应用服务器上实现跨数据库的事务一致性,从而构建更健壮的分布式应用。

    JOTM简单测试DEMO(不含jar包)

    本DEMO主要展示了如何在Spring框架中结合JOTM来处理分布式事务,特别是涉及多个数据源的情况。 首先,我们需要理解JOTM的基本概念。JOTM作为一个事务协调者,负责管理跨多个资源的事务,确保它们要么全部成功,要么...

    jotm2.0最新源码包

    8. **集成与配置**:学习如何将JOTM集成到常见的Java应用服务器(如Tomcat、JBoss等)和Spring框架中,是实际开发中非常实用的部分。 通过深入研究JOTM 2.0的源码,开发者不仅可以掌握事务管理的精髓,还能提升对...

Global site tag (gtag.js) - Google Analytics