Results 1 to 5 of 5

Thread: Newbie: How to prevent the "Overriding bean definition" from occuring

Threaded View

  1. #1
    Join Date
    Apr 2012
    Posts
    3

    Default Newbie: How to prevent the "Overriding bean definition" from occuring

    Good Afternoon,

    This is my very first attempt working with Spring Batch. I am using and following the examples provided in the Spring Batch 2.0 book by Michael T. Minella. I ran into a problem when I tried to run the simple Hello World batch job. The specific issue is that bean definition for bean 'helloWorld' is being overrided by a generic bean.
    I would like to mention that I am compiling, packaging, and executing this job from the Command Prompt as the book has instructed me to do.


    Why is the happening?
    How can I prevent this from happening?
    Is there something that needs to be properly configured in the 'launch-context.xml' file?
    Is there a way that I can disable the overriding in the 'helloWorld.xml' file?

    HelloWorld.java

    Code:
    package com.apress.springbatch.chapter2; 
    
    import org.springframework.batch.core.StepContribution; 
    import org.springframework.batch.core.scope.context.ChunkContext; 
    import org.springframework.batch.core.step.tasklet.Tasklet; 
    import org.springframework.batch.repeat.RepeatStatus; 
    
    /**
    * The HelloWorld tasklet is used to write out a simple message to 
    * standard out durring the processing of your job.
    */
    public class HelloWorld implements Tasklet { 
    
         private static final String HELLO_WORLD = "Hello, world!"; 
    
    	 /**
    	 * {@inheritDoc}
    	 */
         @Override
         public RepeatStatus execute( StepContribution arg0, ChunkContext arg1 ) throws Exception {
              System.out.println( HELLO_WORLD );
              return RepeatStatus.FINISHED; 
         } 
    }
    helloWorld.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?> 
    <beans:beans xmlns ="http://www.springframework.org/schema/batch" 
           xmlns:beans="http://www.springframework.org/schema/beans" 
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           xsi:schemaLocation="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"> 
    
        <beans:import resource="../launch-context.xml"/> 
    
        <!-- The bean that does the work of the job -->
        <beans:bean id="helloWorld" 
                             class="com.apress.springbatch.chapter2.HelloWorld"/> 
    
        <!-- The step definition for the helloWorldJob -->
        <step id="helloWorldStep"> 
            <tasklet ref="helloWorld"/> 
        </step> 
    
        <!-- The job definition for the helloWorldJob -->
        <job id="helloWorldJob"> 
            <step id="step1" parent="helloWorldStep"/> 
        </job>
    </beans:beans>
    launch-context.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
    	xmlns:p="http://www.springframework.org/schema/p" 
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
           	http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    
    	
    
    	<bean id="jobLauncher"
    		class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    		<property name="jobRepository" ref="jobRepository" />
    	</bean>
    	
    	<bean id="jobRepository"
    		class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"
    		p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager" />
    
    	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    		<property name="driverClassName" value="${batch.jdbc.driver}" />
    		<property name="url" value="${batch.jdbc.url}" />
    		<property name="username" value="${batch.jdbc.user}" />
    		<property name="password" value="${batch.jdbc.password}" />
    	</bean>
    
    	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" lazy-init="true">
    		<property name="dataSource" ref="dataSource" />
    	</bean>
    
    	<bean id="placeholderProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		<property name="location" value="classpath:batch.properties" />
    		<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
    		<property name="ignoreUnresolvablePlaceholders" value="true" />
    		<property name="order" value="1" />
    	</bean>
    
    	<!-- Initialize the datasource - remove this bean definition for production use! -->
    	
    </beans>
    Error Message from Command Prompt

    Code:
    C:\Documents and Settings\spring-batch-simple-cli\target>java -jar spr
    ing-batch-simple-cli-2.0.1.RELEASE.jar job/helloWorld.xml helloWorldJob
    Apr 24, 2012 3:06:28 PM org.springframework.context.support.AbstractApplicationC
    ontext prepareRefresh
    INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationCont
    ext@32fb4f: display name [org.springframework.context.support.ClassPathXmlApplic
    ationContext@32fb4f]; startup date [Tue Apr 24 15:06:28 EDT 2012]; root of conte
    xt hierarchy
    Apr 24, 2012 3:06:29 PM org.springframework.beans.factory.xml.XmlBeanDefinitionR
    eader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [job/helloWorld.xml]
    
    Apr 24, 2012 3:06:33 PM org.springframework.beans.factory.xml.XmlBeanDefinitionR
    eader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [launch-context.xml]
    
    Apr 24, 2012 3:06:33 PM org.springframework.beans.factory.support.DefaultListabl
    eBeanFactory registerBeanDefinition
    INFO: Overriding bean definition for bean 'helloWorldJob': replacing [Generic be
    an: class [org.springframework.batch.core.job.flow.support.SimpleFlow]; scope=si
    ngleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; auto
    wireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null;
     initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.spr
    ingframework.batch.core.configuration.xml.JobParserJobFactoryBean]; scope=single
    ton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowire
    Candidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; ini
    tMethodName=null; destroyMethodName=null]
    Apr 24, 2012 3:06:33 PM org.springframework.context.support.AbstractApplicationC
    ontext obtainFreshBeanFactory
    INFO: Bean factory for application context [org.springframework.context.support.
    ClassPathXmlApplicationContext@32fb4f]: org.springframework.beans.factory.suppor
    t.DefaultListableBeanFactory@ce5b1c
    Apr 24, 2012 3:06:34 PM org.springframework.core.io.support.PropertiesLoaderSupp
    ort loadProperties
    INFO: Loading properties file from class path resource [batch.properties]
    Apr 24, 2012 3:06:34 PM org.springframework.beans.factory.support.DefaultListabl
    eBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.
    DefaultListableBeanFactory@ce5b1c: defining beans [jobLauncher,jobRepository,dat
    aSource,transactionManager,placeholderProperties,helloWorld,org.springframework.
    batch.core.scope.internalStepScope,org.springframework.beans.factory.config.Cust
    omEditorConfigurer,org.springframework.batch.core.configuration.xml.CoreNamespac
    ePostProcessor,helloWorldStep,step1,helloWorldJob]; root of factory hierarchy
    Apr 24, 2012 3:06:35 PM org.springframework.batch.core.repository.support.JobRep
    ositoryFactoryBean afterPropertiesSet
    Last edited by mychickbad; Apr 25th, 2012 at 12:23 PM.

Posting Permissions

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