Announcement Announcement Module
Collapse
No announcement yet.
Spring Batch batch:step unable to find reader bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Batch batch:step unable to find reader bean

    Using the Spring Template for creating a Batch Project along with an example provided on the web I constructed a simple batch application. I was able to get it working, and now I am moving the code into my overall Spring application. I do not understand why I am getting an error on the step1 for the reader as the bean is defined. Any insight is greatly appreciated. I am including the error below the code and would like any guidance you could provide. I haven't used Spring Batch so I am sure this is a newbie error but unsure where, and I didn't see anything on the forum which would help me resolve this issue.

    Your insight is greatly appreciated.

    [launch-context.xml]
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:batch="http://www.springframework.org/schema/batch"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
    http://www.springframework.org/schema/batch
    http://www.springframework.org/schem...-batch-2.1.xsd
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <!-- <batch:job-repository id="jobRepository" /> -->

    <import resource="classpath:/module-context.xml" />
    </beans>

    [module-context.xml]

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:batch="http://www.springframework.org/schema/batch"
    xsi:schemaLocation="http://www.springframework.org/schema/batch
    http://www.springframework.org/schem...-batch-2.1.xsd
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <description>Example job to get you started. It provides a skeleton for a typical batch application.</description>

    <batch:job id="job1">
    <batch:step id="step1" >
    <batch:tasklet transaction-manager="transactionManager" >
    <batch:chunk reader="fileReader" writer="fileWriter" commit-interval="10" />
    </batch:tasklet>
    </batch:step>
    </batch:job>

    <bean name="fileReader"
    class="org.springframework.batch.item.file.FlatFil eItemReader">
    <property name="resource" value="file:data/test.txt" />
    <property name="lineMapper" ref="fileLineMapper" />
    </bean>

    <bean name="fileLineMapper"
    class="org.springframework.batch.item.file.mapping .DefaultLineMapper">
    <property name="fieldSetMapper" ref="fileMapper" />
    <property name="lineTokenizer" ref="fileLineTokenizer" />
    </bean>

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

    </beans>

    [MyApp.java]

    ...

    @Autowired
    private static JobLauncher jobLauncher;

    @Autowired
    @Qualifier(value = "job1")
    private static
    Job job;
    ...

    ApplicationContext context =
    new ClassPathXmlApplicationContext("classpath:/launch-context.xml");

    jobLauncher.run(job, new JobParameters());

    ...



    2013-07-08 12:54:52,250 INFO [org.springframework.context.support.ClassPathXmlAp plicationContext] - <Refreshing org.springframework.context.support.ClassPathXmlAp plicationContext@1f243df: startup date [Mon Jul 08 12:54:52 MDT 2013]; root of context hierarchy>
    2013-07-08 12:54:52,358 INFO [org.springframework.beans.factory.xml.XmlBeanDefin itionReader] - <Loading XML bean definitions from class path resource [launch-context.xml]>
    2013-07-08 12:54:52,524 INFO [org.springframework.beans.factory.xml.XmlBeanDefin itionReader] - <Loading XML bean definitions from class path resource [module-context.xml]>
    2013-07-08 12:54:52,732 INFO [org.springframework.beans.factory.support.DefaultL istableBeanFactory] - <Overriding bean definition for bean 'job1': replacing [Generic bean: class [org.springframework.batch.core.configuration.xml.S impleFlowFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.batch.core.configuration.xml.J obParserJobFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]>
    2013-07-08 12:54:52,949 INFO [org.springframework.beans.factory.support.DefaultL istableBeanFactory] - <Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@1eba081: defining beans [org.springframework.batch.core.scope.internalStepS cope,org.springframework.beans.factory.config.Cust omEditorConfigurer,org.springframework.batch.core. configuration.xml.CoreNamespacePostProcessor,step1 ,job1,fileReader,fileLineMapper,fileLineTokenizer]; root of factory hierarchy>
    2013-07-08 12:54:52,988 INFO [org.springframework.beans.factory.support.DefaultL istableBeanFactory] - <Destroying singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@1eba081: defining beans [org.springframework.batch.core.scope.internalStepS cope,org.springframework.beans.factory.config.Cust omEditorConfigurer,org.springframework.batch.core. configuration.xml.CoreNamespacePostProcessor,step1 ,job1,fileReader,fileLineMapper,fileLineTokenizer]; root of factory hierarchy>
    Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'step1': Cannot resolve reference to bean 'fileReader' while setting bean property 'itemReader'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'fileReader' defined in class path resource [module-context.xml]: Cannot resolve reference to bean 'fileLineMapper' while setting bean property 'lineMapper'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'fileLineMapper' defined in class path resource [module-context.xml]: Cannot resolve reference to bean 'fileMapper' while setting bean property 'fieldSetMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'fileMapper' is defined
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:329)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:107)
    at

  • #2
    Disregard. Opened a different thread more in line with the issue.

    Comment

    Working...
    X