Announcement Announcement Module
Collapse
No announcement yet.
Newbie: How to prevent the "Overriding bean definition" from occuring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 12:23 PM.

  • #2
    If you look closer you will see that it is NOT an error it is just an INFO message and not related to your problem. So why should it be an error and what is not happening that you expect to happen.

    Comment


    • #3
      Originally posted by Marten Deinum View Post
      If you look closer you will see that it is NOT an error it is just an INFO message and not related to your problem. So why should it be an error and what is not happening that you expect to happen.
      Ok. But then I am confused. I did not see the output "Hello World" displayed in the Command Prompt

      Comment


      • #4
        Originally posted by Marten Deinum View Post
        If you look closer you will see that it is NOT an error it is just an INFO message and not related to your problem. So why should it be an error and what is not happening that you expect to happen.
        Where it states:

        Code:
        INFO: Overriding bean definition for bean 'helloWorldJob': replacing [Generic be
        an: class [org.springframework.batch.core.job.flow.support.SimpleFlow];
        So is this not overriding the entire bean 'hellowWorldJob'?

        There should be a String displayed as Hello, world! according to book.

        Please advise.

        Comment


        • #5
          I am seeing a similar issue in our Spring environment.

          We have four non-production environments. Three of these show the following message in the trace.log file stating the AXIOM SOAP method is overridden by the SAAJ SOAP method (as we would like). However, in the fourth environment the opposite is happening. The AXIOM is overridding the SAAJ method which causes testing to fail. I commented out the AXIOM bean id information in order to get around the issue but can someone explain why one method is overridding the other?

          2012-12-27 10:50:44,584 [pool-3-thread-1] INFO org.springframework.beans.factory.support.DefaultL istableBeanFactory - Overriding bean definition for bean 'messageFactory': replacing [Generic bean: class [org.springframework.ws.soap.axiom.AxiomSoapMessage Factory]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [/dtciuapp02/las/tcServer/dcis/webapps/dcis/WEB-INF/classes/spring/endpointContext.xml]] with [Generic bean: class [org.springframework.ws.soap.saaj.SaajSoapMessageFa ctory]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [/dtciuapp02/las/tcServer/dcis/webapps/dcis/WEB-INF/classes/spring/webServiceContext.xml]]

          Comment

          Working...
          X