Announcement Announcement Module
Collapse
No announcement yet.
scope="step" not work how I should expect Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • scope="step" not work how I should expect

    Dear Members

    I am working with spring-batch-2.1.0.RELEASE

    I have the follow

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans
        xmlns="http://www.springframework.org/schema/batch"
        xmlns:util="http://www.springframework.org/schema/util"
        xmlns:beans="http://www.springframework.org/schema/beans"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:p="http://www.springframework.org/schema/p"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="
        	http://www.springframework.org/schema/util
    	http://www.springframework.org/schema/util/spring-util-3.0.xsd
    	http://www.springframework.org/schema/beans 
    	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    	http://www.springframework.org/schema/batch
    	http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
    	http://www.springframework.org/schema/aop 
    	http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    	http://www.springframework.org/schema/tx 
    	http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" >
         ...
        <job
            job-repository="jobRepository"
            id="insertIntoDbFromCsvJob">
     
            <step id="step1">
               <tasklet transaction-manager="transactionManager" >
            		<chunk 
            		   reader="csvFileReader"
                              processor = "userRegistrationValidationProcessor"
            	 	   ....
           ...
        </job>
    
        <beans:bean
            scope="step"
            id="csvFileReader"
            class="org.springframework.batch.item.file.FlatFileItemReader"
            p:resource="file:D:/batches/#{jobParameters[input.fileName]}.csv">
            <beans:property name="lineMapper">
    in my Java code I have
    Code:
    jobLauncher.run(job, new JobParametersBuilder().addDate("date", new Date())
    .addString("input.fileName","registrations").toJobParameters());
    I can compile fine, and when I run the code I don't receive any error or exception, the problem is that bean "csvFileReader" not work, I know this because no insertion in the DB happen and my expected output log values not appear, even if I use a non-exist or invalid value for p:resource none error appear

    But If I only change to this instead

    Code:
    <beans:bean
          id="csvFileReader"
          class="org.springframework.batch.item.file.FlatFileItemReader"
          p:resource="file:D:/batches/registrations.csv">
          <beans:property name="lineMapper">
    All work fine

    Therefore what is missing?

    Thanks in advanced

    -Manuel

  • #2
    I too have the similar issue. When I use job parameters, it does not work. If I use static string, it works well. Are you using Spring 3.0?

    Comment


    • #3
      Hello praveens

      No yet, and I didn't try using p:resource with a static value

      -Manuel

      Comment


      • #4
        For the record, here's one config that works fine for us both with Spring 2.5.6 and Spring 3.0.x (Spring Batch 2.1.0)

        Code:
        <bean id="flatFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
                <property name="resource" value="#{jobParameters['sourceFile']}"/>
                <property name="lineMapper">
                    <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
                        <property name="lineTokenizer">
                            <bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
                                <property name="names" value="objectId,version,accountId,balance"/>
                            </bean>
                        </property>
                        <property name="fieldSetMapper">
                            <bean class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
                                <property name="prototypeBeanName" value="prototypeVO"/>
                            </bean>
                        </property>
                    </bean>
                </property>
                <property name="recordSeparatorPolicy">
                    <bean class="org.springframework.batch.item.file.separator.DefaultRecordSeparatorPolicy"/>
                </property>
            </bean>

        Comment


        • #5
          snicoll,
          Can you post the way you are passing your Job variables and loading the job

          Thanks

          Comment


          • #6
            Originally posted by praveens View Post
            snicoll,
            Can you post the way you are passing your Job variables and loading the job

            Thanks
            Loading the job

            Code:
            <bean id="jobLoader" class="org.springframework.batch.core.configuration.support.AutomaticJobRegistrar">
            		<property name="applicationContextFactories">
            			<bean class="org.springframework.batch.core.configuration.support.ClasspathXmlApplicationContextsFactoryBean">
            				<property name="resources" value="classpath*:/jobs/job*.xml" />
            			</bean>
            		</property>
            		<property name="jobLoader">
            			<bean class="org.springframework.batch.core.configuration.support.DefaultJobLoader">
            				<property name="jobRegistry" ref="jobRegistry" />
            			</bean>
            		</property>
            	</bean>

            Variables same as your example.

            Comment


            • #7
              I tried the scope="step" on a simple batch project created from Maven template in 2.3.1.RELEASE. I made the changes to POM to point to Spring 3.0.0.RELEASE and Batch 2.1.0.RELEASE. Still I cannot get the jobParamaters to work. Also I tried to run the test from the main() method instead of using Spring4Unit test case. Still I have the same problem. When I assign #{stepExecution.jobExecution.jobId} to a propertyvalue. The value is set as literal #{stepExecution.jobExecution.jobId} as opposed to correct jobId. The same is the case when I use something like #{jobParameters['User']}.

              Comment


              • #8
                Try stop using the p: namespace and set the value explicitly like in my example.

                Comment

                Working...
                X