Java – no JTA UserTransaction is available – specify ‘UserTransaction’ or ‘usertransactionname’

The Spring Trading encountered a strange problem My application uses spring and EJB EJB also calls the spring service class annotated with @ transaction I use spring JTA transaction manager for transaction management The application is packaged as an ear file and deployed in JBoss 5.0 0, it works normally But when I instruct JBoss to use a separate classloader for each ear application, spring initialization will give an error

org.springframework.beans.factory.BeanCreationException: Error creating bean
   with name 'transactionManager' defined in ServletContext resource 
   [/WEB-INF/applicationContext.xml]: Invocation of init method Failed; 
nested exception is java.lang.IllegalStateException: No JTA UserTransaction 
   available - specify either 'userTransaction' or 'userTransactionName' or 
   'transactionManager' or 'transactionManagerName'

Why failed to initialize spring?

thank you

Solution

Try adding

@EnableTransactionManagement

In a configuration class, you own your configuration bean

When I have this problem, it's useful to me. Maybe you need a transaction manager implemented by other platforms, but it's a good start

@Bean
public PlatformTransactionManager transactionManager() {
    JpaTransactionManager txManager = new JpaTransactionManager();
    txManager.setEntityManagerFactory(entityManagerFactory());
    return txManager;
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>