Java Learing
Java Learing

Reputation: 271

How to convert WebLogicJtaTransactionManager to tomcat supported TransactionManager

As of now we are using weblogic server. So we are using webLogicJtaTransactionManager as shown below.

<bean id="transaction manager" class="org.springframework.transaction.jta.WebLogicJtaTransactionManager" >
<parameter="transactionManagerName" value="javax.transaction.TransactionManger" />
</bean>

Now i want to change above XML to tomcat supported transactionManger. Can you please help how to change this. I tried to deployee in tomcat server with out changing this i am getting below error.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.transaction.TransactionSystemException: Could not initialize WebLogicJtaTransactionManager because WebLogic API classes are not available; nested exception is java.lang.ClassNotFoundException: weblogic.transaction.TransactionHelper

Upvotes: 0

Views: 1385

Answers (1)

eis
eis

Reputation: 53502

For example DataSourceTransactionManager is platform agnostic.

In java config:

import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;

// snip other stuff

@Bean
public PlatformTransactionManager transactionManager() {
    return new DataSourceTransactionManager(dataSource());
}
@Bean
public DataSource dataSource() {
    // create and return a new JDBC DataSource ...
}

in xml config:

<bean id="transactionManager" 
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="datasource" />
</bean>

Your weblogic example has JTA-enabled transaction manager, so it supports distributed transactions, and there is a cross-platform JTA transaction manager in Spring as well, JtaTransactionManager. However since Tomcat doesn't support JTA out of the box, you couldn't use that - using the example above you'll get transactions for your datasource only.

Upvotes: 1

Related Questions