This problem came up today when we ran the abstracttransactionaljunit4springcontexttests test.
Could not find usertransaction in JNDI [java:comp/usertransaction];
My test code
@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> pre-test data </p>
*
* 2012-4-20
* @author Huangchang
*/
@Before
public void Preparetestdata () {
}
@Test
public void Basetest () {
Assert.assertequals (True, true);
}
}
Spring's configuration file
<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>
<!--are going to add these two lines here-->
<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>
The problem will be solved.