Results 1 to 6 of 6

Thread: Trying to invoke a java class within my step

  1. #1

    Default Trying to invoke a java class within my step

    Code:
    		<step id="testStep">
    			<tasklet ref="testBean2"/>
    		</step>
    Code:
    	<bean id="testBean2" class="com.investmaster.util.batch.reader.BatchReaderServersideExecution">
    	</bean>
    Code:
    package com.investmaster.util.batch.reader;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    public class BatchReaderServersideExecution
    {
    
        private static final Logger LOG = LoggerFactory.getLogger(BatchReaderServersideExecution.class);
        
        
        public BatchReaderServersideExecution()
        {
            LOG.info("Inside BatchReaderServersideExecution.. will execute oracle functions inside this class..");
        }
    }
    When I run the job the log trace does actually output:

    13:34:20.533 [main] INFO c.i.u.b.r.BatchReaderServersideExecution - Inside BatchReaderServersideExecution.. will execute oracle functions inside this class..

    But it crashes with this exception:
    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testStep': Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [com.investmaster.util.batch.reader.BatchReaderServersideExecution] to required type [org.springframework.batch.core.step.tasklet.Tasklet] for property 'tasklet'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [com.investmaster.util.batch.reader.BatchReaderServersideExecution] to required type [org.springframework.batch.core.step.tasklet.Tasklet] for property 'tasklet': no matching editors or conversion strategy found
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
    Can someone help me correct this please?
    Many thanks.

  2. #2
    Join Date
    Jul 2010
    Location
    USA
    Posts
    43

    Default

    Your BatchReaderServersideExecution class should implement Tasklet

  3. #3

    Default

    Thanks for the reply Anish, I have made my class implement Tasklet and now get the following error:

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'testBean' defined in class path resource [jobs/auditEventJob.xml]:
    Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: [Assertion failed] - this String argument must have length; it must not be null or empty

  4. #4
    Join Date
    Jul 2010
    Location
    USA
    Posts
    43

    Default

    Scope of the bean which implements tasklet should be 'step'
    e.g. <bean class="com.......tasklet.* " scope="step">


    If it doesnt work, Could you post your code again after you made changes.
    All your business logic(code which calls oracle functions) should be within execute method.

  5. #5

    Default

    I just realised that 'testBean' was another bean I had been messing around with. The code was infact working, I just had forgotten to remove the testBean!! Many thanks anish - implement Tasklet in your first response was all I needed.

    Code:
    package com.investmaster.util.batch.reader;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.batch.core.StepContribution;
    import org.springframework.batch.core.scope.context.ChunkContext;
    import org.springframework.batch.core.step.tasklet.Tasklet;
    import org.springframework.batch.repeat.RepeatStatus;
    import org.springframework.beans.factory.InitializingBean;
    
    public class BatchReaderServersideExecution implements Tasklet
    {
    
        private static final Logger LOG = LoggerFactory.getLogger(BatchReaderServersideExecution.class);
        
        
        public BatchReaderServersideExecution()
        {
            LOG.info("Inside BatchReaderServersideExecution.. will execute oracle functions inside this class..");
        }
    
    
        @Override
        public RepeatStatus execute(StepContribution arg0, ChunkContext arg1) throws Exception
        {
            LOG.info("I have have soemthing here that will execute oracle functions on the database!");
            
            return RepeatStatus.FINISHED;
        }
    }
    My other questino is, is it possible to override RepeatStatus.FINISHED or whatever the return codes are?

    because it would be nice if I could do something like:

    Code:
    		<step id="testStep">
    			<tasklet ref="testBean2"/>
    			<next on="MYRETURNCODE" to="anotherBean"/>
    		</step>
    Last edited by pouncer; Sep 20th, 2010 at 05:30 PM.

  6. #6
    Join Date
    Feb 2011
    Posts
    6

    Default Use StepContribution

    I believe you would use the stepContribution instance to set the exit state.

    Code:
    contribution.setExitStatus(new ExitStatus("MYRETURNCODE"));

Posting Permissions

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