Step 1 - Implementing the transaction manager

Create the bean for the required implementation just like any other Spring bean. You can configure, as appropriate, the transaction manager for any persistence technologies such as JDBC, JMS, JTA, Hibernate, JPA, and so on. But in the following example, here is the manager for a DataSource using JDBC:

In Java configuration, let's see how to define the transactionManager bean in the application:

    @Bean 
    public PlatformTransactionManager transactionManager(DataSource 
dataSource) { return new DataSourceTransactionManager(dataSource); }

In XML configuration, the bean can be created like this:

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

In the preceding code, we use dataSource bean; a dataSource bean must be defined elsewhere. The bean ID, "transactionManager", is the default name. We can change it, but then must specify the alternative name everywhere, and that is not so easy to do!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset