JTA多数据源 Hibernate3.9, Spring 3.1 Could not find UserTransaction in JNDI [java:comp/UserTransaction]
2012-04-20 17:38
471 查看
今天运行AbstractTransactionalJUnit4SpringContextTests的测试的时候出现了这个问题
Could not find UserTransaction in JNDI [java:comp/UserTransaction];
我的测试代码
@ContextConfiguration(locations = {"classpath:applicationContext-resources.xml",
"classpath:applicationContext.xml"})
@TransactionConfiguration(transactionManager="txManager", defaultRollback=true)
public class SystemBaseServiceImplTest extends AbstractTransactionalJUnit4SpringContextTests{
@Override
@Resource(name = "jobcnBossBaseDataSource")
public void setDataSource(DataSource dataSource) {
super.setDataSource(dataSource);
}
/**
* <p>准备测试前的数据</p>
*
* 2012-4-20
* @author 黄昌贤
*/
@Before
public void prepareTestData(){
}
@Test
public void BaseTest(){
Assert.assertEquals(true, true);
}
}
spring的配置文件
<bean id="txManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="allowCustomIsolationLevels" value="true"/>
<property name="userTransaction" ref="jotm" />
</bean>
<bean id="abstractSessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
abstract="true">
<!--<property name="namingStrategy">
<bean class="com.jobcn.boss.web.system.dao.permission.MyNamingStrategy" />
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/jobcn/boss/persistence/base/*.hbm.xml</value>
</list>
</property>
-->
<property name="packagesToScan">
<list>
<value>com.jobcn.boss.persist</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<!-- 要在这里加上这两行 -->
<prop key="hibernate.transaction.factory_class">org.springframework.orm.hibernate3.SpringTransactionFactory</prop>
<prop key="hibernate.transaction.manager_lookup_class">org.springframework.orm.hibernate3.LocalTransactionManagerLookup</prop>
</props>
</property>
<property name="jtaTransactionManager">
<ref bean="jotm" />
</property>
<property name="lobHandler" ref="lobHandler"/>
</bean>
问题就可以解决了
Could not find UserTransaction in JNDI [java:comp/UserTransaction];
我的测试代码
@ContextConfiguration(locations = {"classpath:applicationContext-resources.xml",
"classpath:applicationContext.xml"})
@TransactionConfiguration(transactionManager="txManager", defaultRollback=true)
public class SystemBaseServiceImplTest extends AbstractTransactionalJUnit4SpringContextTests{
@Override
@Resource(name = "jobcnBossBaseDataSource")
public void setDataSource(DataSource dataSource) {
super.setDataSource(dataSource);
}
/**
* <p>准备测试前的数据</p>
*
* 2012-4-20
* @author 黄昌贤
*/
@Before
public void prepareTestData(){
}
@Test
public void BaseTest(){
Assert.assertEquals(true, true);
}
}
spring的配置文件
<bean id="txManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="allowCustomIsolationLevels" value="true"/>
<property name="userTransaction" ref="jotm" />
</bean>
<bean id="abstractSessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
abstract="true">
<!--<property name="namingStrategy">
<bean class="com.jobcn.boss.web.system.dao.permission.MyNamingStrategy" />
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/jobcn/boss/persistence/base/*.hbm.xml</value>
</list>
</property>
-->
<property name="packagesToScan">
<list>
<value>com.jobcn.boss.persist</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<!-- 要在这里加上这两行 -->
<prop key="hibernate.transaction.factory_class">org.springframework.orm.hibernate3.SpringTransactionFactory</prop>
<prop key="hibernate.transaction.manager_lookup_class">org.springframework.orm.hibernate3.LocalTransactionManagerLookup</prop>
</props>
</property>
<property name="jtaTransactionManager">
<ref bean="jotm" />
</property>
<property name="lobHandler" ref="lobHandler"/>
</bean>
问题就可以解决了
相关文章推荐
- 最近用STS搭建hibernate&spring,遇到Could not locate SessionFactory in JNDI.找到这个文章很快解决了
- org.hibernate.PropertyNotFoundException: Could not find a getter for id in class com.pb.dao.UserDao
- java.lang.IllegalStateException: Could not find a method false(View) in the activity class com.xuan
- 安装J2EE的SDK报错:could not find the required version of the Java(TM)2 Runtime Environment in '(null)'的解决
- Could not find the required version of the Java(TM)2 Runtime Environment in '(null)' 解决办法
- JMeter命令行执行及问题解决 Error in NonGUIDriver java.lang.RuntimeException: Could not find the TestPlan class!
- org.hibernate.PropertyNotFoundException: Could not find a getter for titlse in class com.po.Intro异常
- spring+hibernate Could not obtain transaction-synchronized Session for current thread
- org.hibernate.PropertyNotFoundException: Could not find a getter for employee in class com.itcast.f_hbm_oneToMany.Department
- org.apache.ibatis.builder.IncompleteElementException: Could not find result map java.util.Map
- org.apache.ibatis.builder.IncompleteElementException: Could not find result map java.lang.String
- nested exception is org.hibernate.PropertyNotFoundException: Could not find a getter for eNum in class
- hibernate出现:org.hibernate.PropertyNotFoundException: Could not find a getter for id in class
- 安装j2ee 报错 Could not find the required version of the Java(TM)2 Runtime Environment in '(null)'
- 安装J2EE的SDK报错:could not find the required version of the Java(TM)2 Runtime Environment in '(null)'的解决
- IDEA搭建mybatis项目之异常:java.io.IOException: Could not find resource mapping/UserMapper.xml
- DataNode2: java.io.IOException: Could not find my address: datanode2 in list of ZooKeeper quorum ser
- RESTFUL提示java.lang.NoSuchMethodException: Could not find a suitable constructor in
- spring+hibernate工程使用JNDI连接部署至websphere,报错Caused by: java.lang.ClassNotFoundException: oracle.sql.BLO
- Could not find the required version of the Java(TM)2 Runtime Environment in '(null)' 解决办法