我正在处理多模块Maven应用程序,并且Weblogic已经投入生产。堆栈是:
Tomcat 8.5
PostGre 9.6
休眠4.3.8
春季4.1.5
Spring Security 3.2.6
Spring Struts 3.2.13
Prime Faces 5.1
我开始通过在server.xml中创建JNDI数据源和在META-INF / context.xml中创建资源链接(我们将数据库从DB2移至PostGre)进行迁移,但是我遇到了一个例外:
由以下原因引起:java.lang.IllegalStateException:没有可用的JTA UserTransaction -指定“ userTransaction”或“ userTransactionName”或“ transactionManager”或“ transactionManagerName”
我的应用程序位于xml config上,并且我认为错误发生是因为JTA权限已委派给旧版本的weblogic:
DataSourceContext.xml
<?xml version="1.0" encoding="UTF-8"?>
http://www.springframework.org/schema/beans/spring-beans.xsd“>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/mydatasourcename" />
</bean>
<bean id="hibernateProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.query.substitutions">true=1 false=0</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.max_fetch_depth">1</prop>
<prop key="hibernate.default_schema">defaultschemaname</prop>
<!-- How to find the Transaction -->
<prop key="hibernate.transaction.factory_class">org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory
</prop>
<!-- How to produce transaction -->
**<prop key="hibernate.transaction.jta.platform">org.hibernate.engine.transaction.jta.platform.internal.WeblogicJtaPlatform
</prop>**
<!-- Session context with JTA -->
<prop key="current_session_context_class">jta</prop>
</props>
</property>
</bean>
我的Tomcat数据源:
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" readonly="true" type="org.apache.catalina.UserDatabase"/>
<Resource auth="Container" driverClassName="org.postgresql.Driver"
maxIdle="10"
maxTotal="20"
maxWaitMillis="10000"
name="jdbc/*****"
password="*****"
type="javax.sql.DataSource"
url="jdbc:postgresql://********:5432/****"
username="****"/>
</GlobalNamingResources>
休眠配置应用程序ContextDAO.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="packagesToScan">
<list>
<value>package.name</value>
</list>
</property>
<property name="annotatedPackages">
<list>
<value>package.name</value>
</list>
</property>
<property name="hibernateProperties" ref="hibernateProperties" />
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="saveHibernateListener" class="package.name.hibernateListener.SaveHibernateListener"/>
<bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="propertyEditorRegistrars">
<list>
<bean class="package.name.CustomDateEditorRegistrar"/>
</list>
</property>
</bean>
<!-- Template hibernate injecté dans chaque persisteur -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate">
<property name="sessionFactory" ref="mySessionFactory" />
</bean>
</beans>
门面模块applicationContext-transaction.xml
<?xml version="1.0" encoding="UTF-8"?>
http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd“>
<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="get*" propagation="REQUIRED" read-only="true"
rollback-for="ExceptionWork" />
<tx:method name="*" propagation="REQUIRED" rollback-for="MessageException" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="ivaFacadePointcut"
expression="execution(* package.name..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="FacadePointcut" />
</aop:config>
<aop:aspectj-autoproxy proxy-target-class="true"/>
<tx:jta-transaction-manager />
<tx:annotation-driven/>
我认为我必须在DataSourceContext.xml中替换此道具: org.hibernate.engine.transaction.jta.platform.internal.WeblogicJtaPlatform吗?
现有的干净解决方案可以在tomcat 8.5中实现事务管理器吗?还是独立的事务管理器?
对于已经找到的所有解决方案(旧版本的JTA休眠或折旧的JTA),我感到困惑...如果有人可以启发我,我将不胜感激:)
答案 0 :(得分:0)
虽然Weblogic是完整的Application Server,但是Tomcat仅是Web容器。因此,您需要缩小两者之间的一些距离。
交易经理就是其中之一。 Weblogic将“自动”为您添加一个,而Tomcat无法这样做。
如果使用下面的代码片段,则应该可以克服此问题。
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>