Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: Use parameters in job.xml using %%

  1. #11
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    I don't have time to look back at M5, but the latest snapshot has a simple setListeners method. Something like:

    Code:
    defaultStepFactoryBean.setListeners(StepExecutionResourceProxy);
    Of course this would be in xml and not code, but I think you get the idea. I believe in M5 you would need to set that directly on the ItemOrientedStep.
    Last edited by lucasward; Mar 12th, 2008 at 12:23 PM. Reason: fixed code tags

  2. #12
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    Quote Originally Posted by sandrine View Post
    Yes it's used by clientFileWriter which is a FlatFileItemWriter
    And is that file writer used somewhere outside a step? The stack trace might help.

  3. #13

    Default

    here is the log:
    ERROR - BatchMain.start(170) | Job Terminated in error:
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'ExtractionClientsJob' defined in class path resource [jobs/ExtractionClientsJob.xml]: Cannot create inner bean 'Extraction' of type [org.springframework.batch.execution.step.support.D efaultStepFactoryBean] while setting bean property 'steps' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'Extraction' defined in class path resource [jobs/ExtractionClientsJob.xml]: Cannot resolve reference to bean 'clientFileWriter' while setting bean property 'itemWriter'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'clientFileWriter' defined in class path resource [jobs/ExtractionClientsJob.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: The delegate resource has not been initialised. Remember to register this object as a StepListener.
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveInnerBean(BeanDefinitio nValueResolver.java:229)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:117)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveManagedList(BeanDefinit ionValueResolver.java:286)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:126)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1274)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1042)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:485)
    at java.security.AccessController.doPrivileged(Access Controller.java:197)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:455)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 51)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:169)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:248)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:170)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:413)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:735)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:369)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:122)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:66)
    at com.natixis.sphinx.batch.BatchMain.start(BatchMain .java:146)
    at com.natixis.sphinx.batch.BatchMain.main(BatchMain. java:212)
    Caused by:
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'Extraction' defined in class path resource [jobs/ExtractionClientsJob.xml]: Cannot resolve reference to bean 'clientFileWriter' while setting bean property 'itemWriter'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'clientFileWriter' defined in class path resource [jobs/ExtractionClientsJob.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: The delegate resource has not been initialised. Remember to register this object as a StepListener.
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:274)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:104)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1274)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1042)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:485)
    at java.security.AccessController.doPrivileged(Access Controller.java:197)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:455)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveInnerBean(BeanDefinitio nValueResolver.java:219)
    ... 20 more
    Caused by:
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'clientFileWriter' defined in class path resource [jobs/ExtractionClientsJob.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: The delegate resource has not been initialised. Remember to register this object as a StepListener.
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1362)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:540)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:485)
    at java.security.AccessController.doPrivileged(Access Controller.java:197)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:455)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 51)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:169)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:248)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:170)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:268)
    ... 28 more
    Caused by:
    java.lang.IllegalStateException: The delegate resource has not been initialised. Remember to register this object as a StepListener.
    at org.springframework.util.Assert.state(Assert.java: 355)
    at org.springframework.batch.execution.resource.StepE xecutionProxyResource.getFile(StepExecutionProxyRe source.java:132)
    at org.springframework.batch.io.file.FlatFileItemWrit er.afterPropertiesSet(FlatFileItemWriter.java:96)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1390)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1359)
    ... 37 more
    I use a DefaultStepFactoryBean which has a listeners property like ItemOrientedStep has stepListeners property.

    I have seen that in StepExecutionProxyResource there is a field named "delegate" which must not be null but there isn't setDelegate method in this class and so it is always null!!!

    If I am wrong, could you say how to set the delegate?
    Else could you add the setDelegate method in the next version?

    I think I'm going to wait for the next version of spring Batch to use parameter of batch instead of system's parameter.

    Sorry I should have had to see this problem before.

  4. #14

    Default

    Delegate is set when the step starts and calls the beforeStep(..) callback, it's ok there is no setter for it.

  5. #15
    Join Date
    Oct 2004
    Posts
    16

    Default

    This works just fine.

    Here is the job:

    <bean id="fixedLengthFaresAssessorToBlsJob" parent="simpleJob">

    <property name="steps">

    <bean id="stepReadFaresAssessorAndWriteToBls" parent="simpleStep">
    <property name="listeners">
    <list>
    <ref bean="fileResource"/>
    </list>
    </property>
    <!-- need a stream to open record before we read it in -->

    <property name="streams" ref="faresAssessorFlatFileItemReader"/>
    <property name="itemReader" ref="faresAssessorToBlsItemReader"/>
    <property name="itemWriter" ref="blsWriter"/>
    </bean>
    </property>
    </bean>


    and resource:

    <bean id="fileResource" class="org.springframework.batch.execution.resourc e.StepExecutionProxyResource">
    <property name="filePattern" value="data/%file.name%"/>
    </bean>

    <bean id="faresAssessorFlatFileItemReader" class="org.springframework.batch.io.file.FlatFileI temReader">
    <property name="resource" ref="fileResource" />
    <property name="lineTokenizer" ref="faresAssessorFixedFileDescriptor" />
    <property name="fieldSetMapper">
    <bean class="org.springframework.batch.io.file.mapping.P assThroughFieldSetMapper" />
    </property>
    </bean>


    Then just add job parameters as such:

    jpb.addString("file.name", "fixedLengthFaresAssessorToBlsSmallData.txt");
    launcher.run(job,jpb.toJobParameters());


    Thanks.

    Franz Garsombke

  6. #16

    Default

    I have tried with a reader and it works but it doesn't work with a writer.

    Why?

  7. #17
    Join Date
    Jan 2007
    Location
    Taipei, Taiwan
    Posts
    3

    Default

    Because there is a small bug before spring-batch 1.0.1. I have created an issue in the jira. Here is the link http://jira.springframework.org/browse/BATCH-560

    This problem will be fixed in 1.0.1

  8. #18

    Default

    Thank you.

Posting Permissions

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