Announcement Announcement Module
Collapse
No announcement yet.
Problem Running Spring Batch Example without maven Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem Running Spring Batch Example without maven

    Hi All,

    I am very new to Spring Batch. I just tried to run a simple spring batch example which i got from net in vain.The example just tries to read from a flat file and write the contents into a separate flat file.

    Below is my xml which is loaded into context (through a ContextLoaderListener).

    test-batch.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://172.18.7.57/spring-beans.dtd">

    <beans>
    <bean id="simpleJob"
    class="org.springframework.batch.core.job.SimpleJo b">
    <property name="name" value="simpleJob" />
    <property name="steps">
    <list>
    <ref local="step" />
    </list>
    </property>
    <property name="jobRepository" ref="jobRepository" />
    </bean>

    <bean id="jobLauncher"
    class="org.springframework.batch.core.launch.suppo rt.SimpleJobLauncher">
    <property name="jobRepository" ref="jobRepository" />
    </bean>

    <bean id="jobRepository"
    class="org.springframework.batch.core.repository.s upport.SimpleJobRepository">
    <constructor-arg>
    <bean
    class="org.springframework.batch.core.repository.d ao.MapJobInstanceDao" />
    </constructor-arg>
    <constructor-arg>
    <bean
    class="org.springframework.batch.core.repository.d ao.MapJobExecutionDao" />
    </constructor-arg>
    <constructor-arg>
    <bean
    class="org.springframework.batch.core.repository.d ao.MapStepExecutionDao" />
    </constructor-arg>
    </bean>


    <bean id="transactionManager"
    class="org.springframework.batch.support.transacti on.ResourcelessTransactionManager" />

    <bean id="step"
    class="org.springframework.batch.core.step.item.Si mpleStepFactoryBean">
    <property name="transactionManager" ref="transactionManager" />
    <property name="jobRepository" ref="jobRepository" />
    <property name="itemReader" ref="itemReader" />
    <property name="itemWriter" ref="itemWriter" />
    </bean>


    <bean id="lineAggregator"
    class="org.springframework.batch.item.file.transfo rm.DelimitedLineAggregator">
    <property name="delimiter" value="|" />
    </bean>

    <bean id="itemWriter"
    class="org.springframework.batch.item.file.FlatFil eItemWriter">
    <property name="fieldSetCreator" ref="fieldSetMapper" />
    <property name="lineAggregator" ref="lineAggregator" />
    <property name="resource" value="file:/hello2.txt" />
    </bean>

    <bean id="lineTokenizer"
    class="org.springframework.batch.item.file.transfo rm.DelimitedLineTokenizer" />

    <bean id="fieldSetMapper"
    class="org.springframework.batch.item.file.mapping .PassThroughFieldSetMapper" />

    <bean id="itemReader"
    class="org.springframework.batch.item.file.FlatFil eItemReader">
    <property name="resource" value="file:/hello1.txt" />
    <property name="lineTokenizer" ref="lineTokenizer" />
    <property name="fieldSetMapper" ref="fieldSetMapper" />
    </bean>
    </beans>


    As i dont have maven, i tried launching this job from my java code like ,

    ApplicationContext context = new FileSystemXmlApplicationContext("D:\\jboss-4.0.5.GA\\server\\default\\deploy\\test.war\\WEB-INF\\xml\\test-batch.xml");

    Job job;

    job = (Job) context.getBean("simpleJob");
    JobParameters jobParameters = jobParametersConverter

    .getJobParameters(StringUtils
    .splitArrayElementsIntoProperties(new String[]{"D:\\jboss-4.0.5.GA\\server\\default\\deploy\\venki.war\\WEB-INF\\xml\\venki-batch.xml","simpleJob"}, "="));

    JobExecution jobExecution = launcher.run(job, jobParameters);


    --But, some error is thrown in eclipse saying no class loaders found....below is the error i got....

    org.apache.commons.lang.SerializationException: java.lang.ClassNotFoundException: No ClassLoaders found for: org.springframework.batch.core.JobExecution
    at org.apache.commons.lang.SerializationUtils.deseria lize(SerializationUtils.java:164)
    at org.apache.commons.lang.SerializationUtils.deseria lize(SerializationUtils.java:191)
    at org.springframework.batch.core.repository.dao.MapJ obExecutionDao.copy(MapJobExecutionDao.java:33)
    at org.springframework.batch.core.repository.dao.MapJ obExecutionDao.saveJobExecution(MapJobExecutionDao .java:56)
    at org.springframework.batch.core.repository.support. SimpleJobRepository.saveOrUpdate(SimpleJobReposito ry.java:216)
    at org.springframework.batch.core.repository.support. SimpleJobRepository.createJobExecution(SimpleJobRe pository.java:192)
    at org.springframework.batch.core.launch.support.Simp leJobLauncher.run(SimpleJobLauncher.java:79)
    at com.venki.handler.TestHandler.testSpringBatch(Test Handler.java:111)


    --Please help me in this regard...i need to find out a code that reads from a flat file and inserts into a DB....i need to integrate this into a stand alone module and i should not go with using maven....


    Thanks,
    Venkat

  • #2
    I have added spring batch - 1.1.4 (both core and infrastructure) jars along with Spring-core-2.5.5 jar.....

    Comment

    Working...
    X