前段时间在网上看到一位仁兄用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>