Announcement Announcement Module
Collapse
No announcement yet.
problems configuring transaction manager for taskletStep Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • problems configuring transaction manager for taskletStep

    Hello, essentially I'm trying to run an example from http://java.dzone.com/news/spring-batch-hello-world-1 which is a little dated and was probably written for an older version of spring but I believe it should still be valid. I have a tasklet definition:

    <bean id="taskletStep" abstract="true"
    class="org.springframework.batch.core.step.tasklet .TaskletStep">
    <property name="jobRepository" ref="jobRepository"/>
    </bean>


    When I run the program I get an error:
    Error creating bean with name 'taskletStep$child#1bfa3d3' defined in class path resource [simpleJob.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: TransactionManager is mandatory.

    The problem is that I don't have any valid transaction manager bean (i.e. implementing the org.springframework.transaction.PlatformTransactio nManager interface) defined anywhere because this simple test program that does not perform any database access. How do I resolve this? Is there an "empty" or "default" or "dummy" transaction manager implementation I could use?

  • #2
    you could go with the http://static.springsource.org/sprin...moryRepository (ResourcelessTransactionManager is mentioned there too)

    or you could configure a in-memory database with e.g. HSQLDB

    Code:
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
            <property name="url" value="jdbc:hsqldb:mem:testdb" />
            <property name="username" value="sa" />
            <property name="password" value="" />
        </bean>
    
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource" />
        </bean>
    
        <jdbc:initialize-database data-source="dataSource">
            <jdbc:script location="org/springframework/batch/core/schema-hsqldb.sql"/>
        </jdbc:initialize-database>
    needed dependencies

    Code:
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jdbc</artifactId>
                <version>${2.5.6.RELEASE or 3.0.5.RELEASE}</version>
            </dependency>
            <dependency>
                <groupId>commons-dbcp</groupId>
                <artifactId>commons-dbcp</artifactId>
                <version>1.4</version>
            </dependency>
            <dependency>
                <groupId>org.hsqldb</groupId>
                <artifactId>hsqldb</artifactId>
                <version>2.2.4</version>
            </dependency>

    Comment


    • #3
      Thanks. Actually I ended up writing my own transaction manager stub which turned out easier than I thought. Seems to be working...

      public class StubTransactionManager implements PlatformTransactionManager {

      public void commit(TransactionStatus arg0) throws TransactionException {
      }

      public TransactionStatus getTransaction(TransactionDefinition arg0)
      throws TransactionException {
      return new SimpleTransactionStatus();
      }

      public void rollback(TransactionStatus arg0) throws TransactionException {
      }

      }

      Comment

      Working...
      X