您好我正在尝试在myEclipse中为Spring设置spring JTA.Below是我的配置文件:
applicationContent.xml,其中我添加了两个导入(注意它确实包含模式位置)
<import resource="infrastructure.xml"/>
<import resource="classpath:**/persistence.xml"/>
infrastrutre.xml(由于输入验证而无法添加模式)
<bean
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="jtaDataSource" ref="masterDataSource" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
</bean>
<!-- <bean id="masterDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:/test_JTA"></property>
</bean> -->
<jee:jndi-lookup id="masterDataSource" jndi-name="java:/Test_JTA" />
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<!-- <property name="databasePlatform"
value="org.hibernate.dialect.MySQL5InnoDBDialect" /> -->
<property name="database" value="MYSQL" />
<property name="showSql" value="true" />
<property name="generateDdl" value="true" />
</bean>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" />
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="mainPU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.abc.PaymentCard</class>
<jar-file>mysql-connector-java-5.1.23-bin.jar</jar-file>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform"/>
<property key="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
<property key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
</properties>
</persistence-unit>
</persistence>
我收到错误 JBAS010402:无法实例化驱动程序类“com.mysql.jdbc.Driver”:org.jboss.msc.service.DuplicateServiceException:服务jboss.jdbc-driver.JTA_Test_war已注册
我瞥了一眼这个错误,但仍然没有得到任何满意的答案。亲切的帮助
答案 0 :(得分:0)
我不确定JBoss,但对于Glassfish,在Classpath中有一个你想要的Jars的Ext目录。因此,请尝试弄清楚如何将mysql-connector-java * .jar部署到您的域中。
答案 1 :(得分:0)
我知道它已经很晚了,但我相信我通过使用不同的工厂类修复了这个错误。
<property name="hibernate.transaction.factory_class" value="org.hibernate.ejb.transaction.JoinableCMTTransactionFactory"/>
希望它有所帮助:)