Announcement Announcement Module
Collapse
No announcement yet.
No bean named 'transactionManager' is defined Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 02:59 AM.

  • #2
    Do you have a transaction manager named transactionManager in your config?

    Comment


    • #3
      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.

      Comment


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

        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.

        Comment


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

          Comment


          • #6
            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>

            Comment


            • #7
              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?

              Comment


              • #8
                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

                Comment


                • #9
                  That is indeed the class, not sure why I typed management instead of manager...

                  Comment


                  • #10
                    Thanks Marten - everything is now working!

                    Comment

                    Working...
                    X