感谢 @Bond-Java Bond ,解决方案是执行以下步骤:
- 设置
jtaDataSource
为dataSource
。 - 使用
<tx:jta-transaction-manager/>
代替<tx:annotation-driven transaction-manager="transactionManager"/>
。 - 添加
<prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.WeblogicJtaPlatform</prop>
。org.hibernate.service.jta.platform.internal
软件包中有不同的类,可用于不同的Application Server。
因此,最终的Spring xml配置为:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:jee="http://www.springframework.org/schema/jee" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd"> <context:component-scan base-package="testspring.view"/> <context:annotation-config/> <mvc:annotation-driven/> <bean > <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> <mvc:default-servlet-handler/> <bean id="dataSource" name="dataSource" > <property name="jndiName" value="jdbc/hrDS"/> <property name="resourceRef" value="true"/> </bean> <bean /> <bean id="entityManagerFactory" > <property name="jtaDataSource" ref="dataSource"/> <property name="packagesToScan" value="testspring.model"/> <property name="jpaVendorAdapter"> <bean /> </property> <property name="jpaProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop> <prop key="javax.persistence.validation.mode">AUTO</prop> <prop key="hibernate.archive.autodetection">class</prop> <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop> <prop key="hibernate.connection.charSet">UTF-8</prop> <prop key="hibernate.connection.useUnipre">true</prop> <prop key="hibernate.connection.characterEncoding">UTF-8</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.transaction.flush_before_completion">true</prop> <prop key="hibernate.transaction.auto_close_session">true</prop> <prop key="hibernate.connection.release_mode">auto</prop> <prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.WeblogicJtaPlatform</prop> </props> </property> </bean> <tx:jta-transaction-manager/></beans>



