0

I have plain jdbc connection pool in my project and using ejb for transaction. Now I want to change the transaction management to Spring transaction management but, I don't want to create separate datasource for this, I want to use same plain connection pool.

Is it possible to do it?

Below is my spring bean for transaction(datasource is blank as I don't know how to set it from plain jdbc connection pool)

@Bean(name = "transactionManager")
    public DataSourceTransactionManager getTransactionManager() {
        DataSourceTransactionManager txManager = new DataSourceTransactionManager();

        // Get the connection from plain connection pool and set it in datasource

        return txManager;
    }
Manas B
  • 5
  • 2

1 Answers1

1

It's a Bean under the Spring factory's control, so you can inject it.

Try this:

@Bean(name = "transactionManager")
public DataSourceTransactionManager getTransactionManager(@Qualifier("dataSource") DataSource dataSource) {
    return new DataSourceTransactionManager(dataSource);
}
duffymo
  • 305,152
  • 44
  • 369
  • 561