Prakash Mondal

Prakash Mondal

  • NA
  • 288
  • 209.1k

How to use transaction manager in Spring Framework?

Jul 5 2019 9:32 AM
In applicationContext.xml, I write this bellow code:
 
 <bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"
          p:driverClassName="org.postgresql.Driver"
          p:url="jdbc:postgresql://localhost:5432/SampleDB"
          p:username="postgres"
          p:password="Password" />   
     
    <bean id="transactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref= "dataSource" />
    </bean>
    <bean id="registrationService" class = "com.test.Service.RegistrationService">
        <property name="dataSource" ref="dataSource" />
    </bean>
 
Controller Part:
 
ApplicationContext appctx = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getServletContext());
        RegistrationService service = (RegistrationService) appctx.getBean("registrationService");
 
 
Service Part:
 
@Transactional(value = "transactionManager", rollbackFor=Exception.class)
 
 
But error occured. 
Please help.
Any body can suggest me the another process.