Results 1 to 10 of 10

Thread: No bean named 'transactionManager' is defined

  1. #1
    Join Date
    May 2012
    Posts
    18

    Default No bean named 'transactionManager' is defined

    Receiving a No bean named 'transactionManager' is defined

    1) Here is the Junit4 class(transactionManager has no space between n and s):

    @RunWith(SpringJUnit4ClassRunner.class)
    @Transactional(propagation=Propagation.REQUIRED)
    @ContextConfiguration(locations = { "classpath:resources/Spring-Module.xml" })
    @TransactionConfiguration(transactionManager="tran sactionManager", defaultRollback=true)
    public class TestApp {

    @Autowired
    CustomerDAO customerDAO;

    @Transactional
    @Test
    public void testDB() {

    Customer customer = new Customer(1, "mkyong", 28);
    customerDAO.insert(customer);
    Assert.assertEquals("Success", 1, 1);
    }

    }

    2) Below is the Spring configuration

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

    <bean id="dataSource" class="org.springframework.jdbc.datasource.Transac tionAwareDataSourceProxy">
    <constructor-arg ref="dataSourceOrg"/>
    </bean>

    <bean id="dataSourceOrg" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/mkyongjava" />
    <property name="username" value="root" />
    <property name="password" value="xxxxxx />
    </bean>

    </beans>
    Last edited by java2design; Jun 3rd, 2013 at 01:59 AM.

  2. #2
    Join Date
    Dec 2010
    Location
    Singapore
    Posts
    302

    Default

    Do you have a transaction manager named transactionManager in your config?
    Amila Domingo

  3. #3
    Join Date
    May 2012
    Posts
    18

    Default

    The objective is to use Spring with legacy jdbc code. Therefore, wrapping datasource with TransactionAwareDataSourceProxy in the Spring config- see explanation below:

    Alternatively, you can allow application code to work with the standard J2EE-style lookup pattern DataSource.getConnection(), for example for legacy code that is not aware of Spring at all. In that case, define a TransactionAwareDataSourceProxy for your target DataSource, and pass that proxy DataSource to your DAOs, which will automatically participate in Spring-managed transactions when accessing it.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Read the stacktrace... It tells you what is missing, you don't have a transaction manager..

    Quote Originally Posted by java2design
    which will automatically participate in Spring-managed transactions when accessing it.
    And how do you think spring manages a transaction? Magic? No it needs a transaction manager.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    May 2012
    Posts
    18

    Default

    Thanks for responding..what is the XML to add to the Spring-config for Transaction manager?

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Depends on what technology you use, judging from your xml you are using plain JDBC.

    Code:
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManagement">
      <property name="dataSource" ref="dataSourceOrg" />
    </bean>
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  7. #7
    Join Date
    May 2012
    Posts
    18

    Default

    I getting a Cannot find class [org.springframework.jdbc.datasource.DataSourceTran sactionManagement] when I added the above XML, yet it finds org.springframework.jdbc.datasource.DriverManagerD ataSource, which is in the same jar?

  8. #8
    Join Date
    May 2012
    Posts
    18

    Default

    Thanks for responding Marten Deinum!

    Found the class not found issue. Did you mean:

    org.springframework.jdbc.datasource.DataSourceTran sactionManager

    instead of

    org.springframework.jdbc.datasource.DataSourceTran sactionManagement

    because class DataSourceTransactionManagement does not exist in jar file spring-jdbc.jar file

  9. #9
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    That is indeed the class, not sure why I typed management instead of manager...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  10. #10
    Join Date
    May 2012
    Posts
    18

    Default

    Thanks Marten - everything is now working!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •