Announcement Announcement Module
Collapse
No announcement yet.
VOID main for spring batch example Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • VOID main for spring batch example

    Encountered an error executing the step
    java.lang.NullPointerException
    at org.batch.PlanWriter.write(PlanWriter.java:21)
    at org.springframework.batch.core.step.item.SimpleChu nkProcessor.writeItems(SimpleChunkProcessor.java:

    HTML Code:
    	<bean id="dataSource"
    		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
    		<property name="url"
    			value="jdbc:oracle:thin:@ut:1010:orcl" />
    		<property name="username" value="rf" />
    		<property name="password" value="fr" />
    	</bean>
    
    	<bean id="transactionManager"
    		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    		<property name="dataSource" ref="dataSource" />
    	</bean>
    	<tx:annotation-driven transaction-manager="transactionManager" />
    
    	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    		<property name="dataSource" ref="dataSource" />
    	</bean>
    
    
    <bean id="asyncTaskExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
    	<bean id="syncTaskExecutor" class="org.springframework.core.task.SyncTaskExecutor" />
    
    	<bean id="params" class="org.springframework.batch.core.JobParameters" />
    	 
    	<bean id="jobRepository"
    		class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
    		<property name="transactionManager" ref="transactionManager" />
    	 
    	</bean>
    
    
    	 
    	<bean id="jobLauncher"
    		class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    		<property name="jobRepository" ref="jobRepository" />
    	</bean>
    
    	<bean id="simpleStep"
    		class="org.springframework.batch.core.step.item.SimpleStepFactoryBean"
    		abstract="true">
    		<property name="transactionManager" ref="transactionManager" />
    		<property name="jobRepository" ref="jobRepository" />
     
    	</bean>
    	
    	
    	<batch:job id="simpleJob" job-repository="jobRepository">
    		<batch:listeners>
    			<batch:listener ref="appJobExecutionListener" />
    		</batch:listeners>
    		<batch:step id="planload" next="deleteFilesInDir" parent="simpleStep" >
    			<batch:tasklet  >
    				<batch:listeners>
    					<batch:listener ref="itemFailureLoggerListener" />
    				</batch:listeners>
    				<batch:chunk reader="itemReader" writer="itemWriter"
    					commit-interval="1000" />
    			</batch:tasklet>
    		</batch:step>
    		<batch:step id="deleteFilesInDir" parent="simpleStep">
    			<batch:tasklet ref="fileDeletingTasklet" />
    		</batch:step>
    	</batch:job>
    
     
    	<bean id="itemReader" class="org.springframework.batch.item.file.FlatFileItemReader" >
    
    		<property name="resource" value="file:c:\data\input\plans\plan.csv" />
    
    		<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="col1,col2,col3,col4" />
    					</bean>
    				</property>
    				<property name="fieldSetMapper" ref="planMapper" />
    			</bean>
    		</property>
    	</bean>
    
    
    	<bean id="fileDeletingTasklet" class="org.batch.util.FileDeletingTasklet">
    		<property name="directoryResource">
    			<bean id="directory" class="org.springframework.core.io.FileSystemResource">
    				<constructor-arg value="C:\data\input\plans\plan.csv" />
    			</bean>
    		</property>
    	</bean>
    
    </beans>

    main contains
    HTML Code:
    Resource res = new ClassPathResource("org/batch/csv2temp.xml"); 
    		BeanFactory fac = new XmlBeanFactory(res);
    		JobLauncher launcher = (JobLauncher)fac.getBean("jobLauncher");
    		Job job = (Job)fac.getBean("simpleJob");
    		JobParameters params = (JobParameters)fac.getBean("params");
    Wahts wrong in that.
    Last edited by fusionobject; Jun 16th, 2011, 10:53 AM.

  • #2
    it's hard to tell, because the null pointer exception comes from your code (PlanWriter). When launching the job, try to use an ApplicationContext implementation (like ClasspathXmlApplicationContext) instead of a BeanFactory.

    Comment


    • #3
      can you please guide me to Some sample for that ?

      Comment


      • #4
        try this first:

        Code:
        ApplicationContext ctx = new ClassPathXmlApplicationContext("org/batch/csv2temp.xml");
        JobLauncher launcher = (JobLauncher) ctx.getBean("jobLauncher");
        ...

        Comment

        Working...
        X