Announcement Announcement Module
Collapse
No announcement yet.
How do I use CommandLineJobRunner? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I use CommandLineJobRunner?

    Excuse my beginner ignorance , but the documentation seems slightly overwhelming for me, and I'd like to just get things working before I get too confused.

    I'm using Linux, trying to run spring batch. I'm reading the user guide for spring batch, and it says to run:

    $ java CommandLineJobRunner

    Now, I've installed spring batch (version 2.1.8). The above command says class not found. Is the user guide wrong or is there a missing step that I'm supposed to know about here?

    I'd appreciate even a workaround to get this working.

    P.S. - I've tried
    $ java -classpath /home/jay/spring-batch/spring-batch-core/target/classes/org/springframework/batch/core/launch/support/ org.springframework.batch.core.launch.support.Comm andLineJobRunner
    I still get ClassNotFoundException
    Last edited by notfed; Jun 20th, 2011, 03:49 PM.

  • #2
    So, to recap, when I make sure CommandLineJobRunner.class is in my CLASSPATH, and I do this:
    Code:
    $  java org.springframework.batch.core.launch.support.CommandLineJobRunner testjob.xml testjob schedule.date=2011/06/21
    The result is this error:

    Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/ConfigurableApplicationContext
    Caused by: java.lang.ClassNotFoundException: org.springframework.context.ConfigurableApplicationContext
            at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    Could not find the main class: org.springframework.batch.core.launch.support.CommandLineJobRunner.  Program will exit.

    Comment


    • #3
      Same thing if I do the following (including spring-batch-core[...].jar in classpath):

      Code:
      java -classpath /home/jay/spring-batch/spring-batch-core/target/spring-batch-core-2.1.8.RELEASE.jar org.springframework.batch.core.launch.support.CommandLineJobRunner test_batch_job.xml test_batch schedule.date=2011/06/21

      Comment


      • #4
        Does this mean I need org.springframework.context. ConfigurableApplicationContext? Where do I get this? I don't see this class in either spring-batch-core-2.1.8.RELEASE.jar or spring-batch-infrastructure-2.1.8.RELEASE.jar. I see a list of possible jars that contain this class, but I'm not sure which version I should use. Can anyone offer some advice?
        Last edited by notfed; Jun 22nd, 2011, 10:27 AM.

        Comment


        • #5
          I decided to track down the missing class (found it in spring-1.2.3.jar), then track down another missing class (found in commons-logging-1.1.jar), and download the jars from the internet. No idea if they're the right version.

          So I did:

          Code:
          $ wget http://mirrors.ibiblio.org/pub/mirrors/maven2/commons-logging/commons-logging/1.1/commons-logging-1.1.jar
          $ wget http://mirrors.ibiblio.org/pub/mirrors/maven2/org/springframework/spring/1.2.3/spring-1.2.3.jar
          To get the missing jar files. Then I did:

          Code:
          $ java -classpath .:spring-batch-core-2.1.8.RELEASE.jar:spring-batch-infrastructure-2.1.8.RELEASE.jar:spring-1.2.3.jar:commons-logging-1.1.jar org.springframework.batch.core.launch.support.CommandLineJobRunner simpleJob.xml simpleJob
          And got the error:

          Code:
          Jun 22, 2011 11:40:06 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
          INFO: Loading XML bean definitions from class path resource [simpleJob.xml]
          Jun 22, 2011 11:40:06 AM org.springframework.batch.core.launch.support.CommandLineJobRunner start
          SEVERE: Job Terminated in error: Line 3 in XML document from class path resource [simpleJob.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".
          org.springframework.beans.factory.BeanDefinitionStoreException: Line 3 in XML document from class path resource [simpleJob.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".
          org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 131; Document root element "beans", must match DOCTYPE root "null".
                  at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
                  at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
                  at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:387)
                  at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:321)
                  at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.rootElementSpecified(XMLDTDValidator.java:1624)
                  at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(XMLDTDValidator.java:1903)
                  at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:767)
                  at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1340)
                  at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(XMLDocumentScannerImpl.java:1293)
                  at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3080)
                  at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:899)
                  at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:625)
                  at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
                  at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:812)
                  at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:741)
                  at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
                  at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:239)
                  at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:288)
                  at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
                  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:153)
                  at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:124)
                  at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:140)
                  at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:103)
                  at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:71)
                  at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:87)
                  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:267)
                  at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:80)
                  at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65)
                  at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:56)
                  at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:282)
                  at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574)
          So….what do I do here? [ Document root element "beans", must match DOCTYPE root "null". ] ?!? Say what??

          Comment


          • #6
            I tried using references from spring-framework-3.1.0.M2 instead of from some random place on the internet (and downloaded commons-logging-1.1.1.jar), and my error changed to this:

            Code:
            $ java -classpath .:spring-batch-core-2.1.8.RELEASE.jar:spring-batch-infrastructure-2.1.8.RELEASE.jar:org.springframework.context-3.1.0.M2.jar:org.springframework.core-3.1.0.M2.jar:org.springframework.beans-3.1.0.M2.jar:commons-logging-1.1.1.jar:org.springframework.asm-3.1.0.M2.jar org.springframework.batch.core.launch.support.CommandLineJobRunner simpleJob.xml simpleJob
            Jun 22, 2011 12:53:40 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
            INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@50ef5502: startup date [Wed Jun 22 12:53:40 EDT 2011]; root of context hierarchy
            Jun 22, 2011 12:53:40 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
            INFO: Loading XML bean definitions from class path resource [simpleJob.xml]
            Jun 22, 2011 12:53:40 PM org.springframework.batch.core.launch.support.CommandLineJobRunner start
            SEVERE: Job Terminated in error: Line 37 in XML document from class path resource [simpleJob.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 37; columnNumber: 22; cvc-complex-type.2.3: Element 'bean' cannot have character [children], because the type's content type is element-only.
            org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 37 in XML document from class path resource [simpleJob.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 37; columnNumber: 22; cvc-complex-type.2.3: Element 'bean' cannot have character [children], because the type's content type is element-only.
                    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
                    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
                    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
                    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
                    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
                    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
                    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
                    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
                    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
                    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
                    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522)
                    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)
                    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
                    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
                    at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:282)
                    at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574)
            Caused by: org.xml.sax.SAXParseException; lineNumber: 37; columnNumber: 22; cvc-complex-type.2.3: Element 'bean' cannot have character [children], because the type's content type is element-only.
                    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
                    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
                    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:387)
                    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:321)
                    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:421)
                    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3185)
                    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.elementLocallyValidComplexType(XMLSchemaValidator.java:3148)
                    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.elementLocallyValidType(XMLSchemaValidator.java:3108)
                    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processElementContent(XMLSchemaValidator.java:3010)
                    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleEndElement(XMLSchemaValidator.java:2153)
                    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.endElement(XMLSchemaValidator.java:821)
                    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1759)
                    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2915)
                    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:625)
                    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
                    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
                    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:812)
                    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:741)
                    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
                    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:239)
                    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:288)
                    at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
                    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
                    ... 15 more
            So I'm now using the following jars:

            Code:
            spring-batch-core-2.1.8.RELEASE.jar
            spring-batch-infrastructure-2.1.8.RELEASE.jar
            org.springframework.asm-3.1.0.M2.jar
            org.springframework.beans-3.1.0.M2.jar
            org.springframework.context-3.1.0.M2.jar
            org.springframework.core-3.1.0.M2.jar
            commons-logging-1.1.1.jar
            Can anyone tell me what I'm doing majorly wrong? I don't think I'm supposed to have to go through all of this...I'm hoping there's some obvious step I missed.
            Last edited by notfed; Jun 22nd, 2011, 11:59 AM.

            Comment


            • #7
              Hi notfed,

              This seems an XML parsing error. Do you mind posting your simpleJob.xml?

              Thanks,


              nicolas.loriente

              Comment


              • #8
                Okay, turns out I had an extra semicolon in the simpleJob.xml, doh.

                New simpleJob.xml:
                Code:
                <beans xmlns="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-2.5.xsd">
                
                  <import resource="applicationContext.xml"/>
                
                  <bean id="hello" class="helloworld.PrintTasklet">
                      <property name="message" value="Hello"/>
                  </bean>
                
                  <bean id="space" class="helloworld.PrintTasklet">
                      <property name="message" value=" "/>
                  </bean>
                
                  <bean id="world" class="helloworld.PrintTasklet">
                      <property name="message" value="World!"/>
                  </bean>
                
                  <bean id="taskletStep" abstract="true"
                      class="org.springframework.batch.core.step.tasklet.TaskletStep">
                      <property name="jobRepository" ref="jobRepository"/>
                  </bean>
                
                  <bean id="simpleJob" class="org.springframework.batch.core.job.SimpleJob">
                      <property name="name" value="simpleJob" />
                      <property name="steps">
                          <list>
                              <bean parent="taskletStep">
                                  <property name="tasklet" ref="hello"/>
                              </bean>
                              <bean parent="taskletStep">
                                  <property name="tasklet" ref="space"/>
                              </bean>
                              <bean parent="taskletStep">
                                  <property name="tasklet" ref="world"/>
                              </bean>
                          </list>
                      </property>
                      <property name="jobRepository" ref="jobRepository"/>
                  </bean>
                </beans>
                Next error is this:

                Code:
                Jun 22, 2011 4:55:51 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
                INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@50ef5502: startup date [Wed Jun 22 16:55:51 EDT 2011]; root of context hierarchy
                Jun 22, 2011 4:55:51 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
                INFO: Loading XML bean definitions from class path resource [simpleJob.xml]
                Jun 22, 2011 4:55:52 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
                INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
                Jun 22, 2011 4:55:52 PM org.springframework.batch.core.launch.support.CommandLineJobRunner start
                SEVERE: Job Terminated in error: org/springframework/expression/PropertyAccessor
                java.lang.NoClassDefFoundError: org/springframework/expression/PropertyAccessor
                        at org.springframework.context.support.AbstractApplicationContext.prepareBeanFactory(AbstractApplicationContext.java:538)
                        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:439)
                        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
                        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
                        at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:282)
                        at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574)
                Caused by: java.lang.ClassNotFoundException: org.springframework.expression.PropertyAccessor
                        at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
                        at java.security.AccessController.doPrivileged(Native Method)
                        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
                        at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
                        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
                        at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
                        ... 6 more
                Almost seems like it's working..I can't tell, what is this error?

                Comment


                • #9
                  Okay, I had to add the spring expressions jar.

                  My prompt (to run this thing) has now become:

                  Code:
                  java -classpath .:spring-batch-core-2.1.8.RELEASE.jar:spring-batch-infrastructure-2.1.8.RELEASE.jar:org.springframework.context-3.1.0.M2.jar:org.springframework.core-3.1.0.M2.jar:org.springframework.beans-3.1.0.M2.jar:commons-logging-1.1.1.jar:org.springframework.asm-3.1.0.M2.jar:org.springframework.expression-3.1.0.M2.jar:org.springframework.transaction-3.1.0.M2.jar org.springframework.batch.core.launch.support.CommandLineJobRunner simpleJob.xml simpleJob
                  Now, here's the result:
                  Code:
                  Jun 22, 2011 5:03:12 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
                  INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@50ef5502: startup date [Wed Jun 22 17:03:12 EDT 2011]; root of context hierarchy
                  Jun 22, 2011 5:03:12 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
                  INFO: Loading XML bean definitions from class path resource [simpleJob.xml]
                  Jun 22, 2011 5:03:13 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
                  INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
                  Jun 22, 2011 5:03:13 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
                  INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@28e70e30: defining beans [jobLauncher,jobRepository,hello,space,world,taskletStep,simpleJob]; root of factory hierarchy
                  Jun 22, 2011 5:03:13 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
                  INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@28e70e30: defining beans [jobLauncher,jobRepository,hello,space,world,taskletStep,simpleJob]; root of factory hierarchy
                  Jun 22, 2011 5:03:13 PM org.springframework.batch.core.launch.support.CommandLineJobRunner start
                  SEVERE: Job Terminated in error: Error creating bean with name 'jobLauncher' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'jobRepository' while setting bean property 'jobRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository' defined in class path resource [applicationContext.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
                  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobLauncher' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'jobRepository' while setting bean property 'jobRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository' defined in class path resource [applicationContext.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
                          at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
                          at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
                          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
                          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
                          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
                          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
                          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
                          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
                          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
                          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
                          at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
                          at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
                          at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
                          at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
                          at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
                          at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:282)
                          at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574)
                  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository' defined in class path resource [applicationContext.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
                          at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:250)
                          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1003)
                          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:907)
                          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
                          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
                          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
                          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
                          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
                          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
                          at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
                          ... 16 more
                  Don't know what to think of that, it's not a ClassNotFoundException anymore.

                  I'll post the source to my other files (there's 3: simpleJob.xml, applicationContext.xml, and PrintTasklet.java):

                  applicationContext.xml
                  Code:
                  <?xml version="1.0" encoding="UTF-8"?>
                  <beans xmlns="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-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.SimpleJobRepository">
                        <constructor-arg>
                            <bean class="org.springframework.batch.core.repository.dao.MapJobInstanceDao"/>
                        </constructor-arg>
                        <constructor-arg>
                            <bean class="org.springframework.batch.core.repository.dao.MapJobExecutionDao" />
                        </constructor-arg>
                        <constructor-arg>
                            <bean class="org.springframework.batch.core.repository.dao.MapStepExecutionDao"/>
                        </constructor-arg>
                    </bean>
                  
                  </beans>
                  PrintTasklet.java
                  Code:
                  package org.petio.tryspringbatch;
                  
                  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;
                  
                  @SuppressWarnings("unchecked")
                  public class PrintTasklet implements Tasklet
                  {
                          private String message;
                          public void setMessage(String message)
                          {
                                  this.message = message;
                          }
                  
                          public RepeatStatus execute(StepContribution arg0, ChunkContext arg1) throws Exception
                          {
                                  System.out.print(message);
                                  return RepeatStatus.FINISHED;
                          }
                  }

                  Comment


                  • #10
                    notfed,

                    A couple of things:

                    1. If I were you I would look into using a dependency management solution such as Maven. The time you invest learning it it will be well worth it and you'll save all the effort and time of figuring out in what jars classes are and downloading them. You declare your basic dependencies and Maven brings in all other complile dependencies your dependencies have. It also can download source code for you and much more.

                    2. The issue you are facing now is a constructor type ambiguity issue. The problem is with your "jobRepository".
                    [QUOTE]Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'jobRepository' defined in class path resource [applicationContext.xml] Look at the following example:

                    Code:
                    public class SomeBean {
                        .....
                    
                        // first constructor
                        public SomeBean( String str1, String str2 ) {
                        .....
                        }
                    
                        // second constructor
                        public SomeBean( int int1, String str1 ) {
                        .....
                        }
                    }
                    Code:
                    <bean id="someBean" class="com.beans.SomeBean">
                        <constructor-arg value="7500000"/>
                        <constructor-arg value="42"/>
                    </bean>
                    Spring won't know if to use the (string, string) or the (int, string) constructor.

                    As the exception and documentation state:
                    Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
                    You can help out Spring when facing ambiguity by providing an extra parameter on the constructor-arg element:

                    Code:
                    <bean id="someBean" class="com.beans.SomeBean">
                        <constructor-arg index="0" value="7500000"/>
                        <constructor-arg index="1" value="42"/>
                    </bean>
                    Code:
                    <bean id="someBean" class="com.beans.SomeBean">
                        <constructor-arg type="int" value="7500000"/>
                        <constructor-arg type="java.lang.String" value="42"/>
                    </bean>
                    Code:
                    <bean id="someBean" class="com.beans.SomeBean">
                        <constructor-arg name="int1" value="7500000"/>
                        <constructor-arg name="str1" value="42"/>
                    </bean>
                    3. Here is a link to your development Bible http://static.springsource.org/sprin...reference.html. It has almost all the answers you'll ever need. And if you have questions or do not understand some concepts we'll be here to give you a hand.


                    nicolas.loriente
                    Last edited by nicolas.loriente; Jun 22nd, 2011, 06:25 PM.

                    Comment


                    • #11
                      So, I read up on maven and created a few sample apps with it. So, how would I have maven automatically fetch these jars for me? I don't know what libraries and versions to use, so how would maven figure this out?

                      Also, the jobRepository. I'm simply following a tutorial at http://java.dzone.com/news/spring-batch-hello-world-1. I am doing this completely blind, in the dark. Only vaguely understand each part, here. Am I supposed to have a jobRepository class that I can edit? I don't have one, so I don't know about those ambiguous constructors. I'd think this tutorial would have correct data and I'm assuming if it's not building then it's something I did wrong.

                      Comment


                      • #12
                        you can try this: https://github.com/acogoluegnes/Spring-Batch-Workshop

                        there's an hello world example. You need an IDE with Maven support (download SpringSource Tool Suite for example, which is based on Eclipse). You can then import the workshop as Maven projects and follow the TODOs.

                        Comment


                        • #13
                          Thanks, I downloaded SpringSource Tool Suite. Then I imported the hello-world-start maven project into it and loaded it up.

                          I noticed the Spring-Batch-Workshop project says, in the README, "The concepts are (quickly) covered in the PDF file at the root of this project. The PDF contains additional instructions and hints to work on the projects." There are no PDFs in the project. So I really already feel discouraged here.

                          It was able to compile fine, but I can't figure out how to get it to run. I tried configuring my build according to ( http://victor-jan.blogspot.com/2010/...ng-spring.html )--that is, created a new Run Configuration to run:

                          Code:
                          org.springframework.batch.core.launch.support.CommandLineJobRunner hello-world-job.xml HelloWorldTasklet time=11:06AM
                          The error upon building is this:

                          Code:
                          14:01:10.001 [main] INFO  o.s.c.s.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@defa1a: startup date [Thu Jun 23 14:01:09 EDT 2011]; root of context hierarchy
                          14:01:10.093 [main] INFO  o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [hello-world-job.xml]
                          14:01:10.119 [main] DEBUG o.s.b.f.xml.DefaultDocumentLoader - Using JAXP provider [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl]
                          14:01:10.163 [main] DEBUG o.s.b.f.xml.PluggableSchemaResolver - Loading schema mappings from [META-INF/spring.schemas]
                          14:01:10.168 [main] DEBUG o.s.b.f.xml.PluggableSchemaResolver - Loaded schema mappings: {http://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-3.0.xsd, 
                          ...
                          14:01:10.171 [main] DEBUG o.s.b.f.xml.PluggableSchemaResolver - Found XML schema [http://www.springframework.org/schema/beans/spring-beans-3.0.xsd] in classpath: org/springframework/beans/factory/xml/spring-beans-3.0.xsd
                          14:01:10.244 [main] DEBUG o.s.b.f.x.DefaultBeanDefinitionDocumentReader - Loading bean definitions
                          14:01:10.276 [main] DEBUG o.s.b.f.xml.XmlBeanDefinitionReader - Loaded 3 bean definitions from location pattern [hello-world-job.xml]
                          14:01:10.276 [main] DEBUG o.s.c.s.ClassPathXmlApplicationContext - Bean factory for org.springframework.context.support.ClassPathXmlApplicationContext@defa1a: org.springframework.beans.factory.support.DefaultListableBeanFactory@1a9334: defining beans [transactionManager,jobRepository,jobLauncher]; root of factory hierarchy
                          14:01:10.313 [main] DEBUG o.s.c.s.ClassPathXmlApplicationContext - Unable to locate MessageSource with name 'messageSource': using default [[email protected]a]
                          14:01:10.322 [main] DEBUG o.s.c.s.ClassPathXmlApplicationContext - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@5a9de6]
                          14:01:10.323 [main] INFO  o.s.b.f.s.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1a9334: defining beans [transactionManager,jobRepository,jobLauncher]; root of factory hierarchy
                          14:01:10.324 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'transactionManager'
                          14:01:10.324 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'transactionManager'
                          14:01:10.368 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'transactionManager' to allow for resolving potential circular references
                          14:01:10.370 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'transactionManager'
                          14:01:10.370 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'jobRepository'
                          14:01:10.370 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'jobRepository'
                          14:01:10.377 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'jobRepository' to allow for resolving potential circular references
                          14:01:10.377 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'jobRepository'
                          14:01:10.405 [main] DEBUG o.s.t.i.NameMatchTransactionAttributeSource - Adding transactional method[*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT]
                          14:01:10.405 [main] DEBUG o.s.t.i.NameMatchTransactionAttributeSource - Adding transactional method [create*] with attribute [PROPAGATION_REQUIRES_NEW,ISOLATION_SERIALIZABLE]
                          14:01:10.406 [main] DEBUG o.s.t.i.NameMatchTransactionAttributeSource - Adding transactional method [getLastJobExecution*] with attribute [PROPAGATION_REQUIRES_NEW,ISOLATION_SERIALIZABLE]
                          14:01:10.435 [main] DEBUG o.s.aop.framework.JdkDynamicAopProxy - Creating JDK dynamic proxy: target source is SingletonTargetSource for target object [java.util.concurrent.ConcurrentHashMap@5f8172]
                          14:01:10.464 [main] DEBUG o.s.aop.framework.JdkDynamicAopProxy - Creating JDK dynamic proxy: target source is SingletonTargetSource for target object [java.util.concurrent.ConcurrentHashMap@87c268]
                          14:01:10.465 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'jobRepository'
                          14:01:10.466 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'jobLauncher'
                          14:01:10.467 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'jobLauncher'
                          14:01:10.470 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'jobLauncher' to allow for resolving potential circular references
                          14:01:10.490 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'jobRepository'
                          14:01:10.491 [main] DEBUG o.s.aop.framework.JdkDynamicAopProxy - Creating JDK dynamic proxy: target source is SingletonTargetSource for target object [org.springframework.batch.core.repository.support.SimpleJobRepository@ba8602]
                          14:01:10.519 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'jobLauncher'
                          14:01:10.520 [main] INFO  o.s.b.c.l.support.SimpleJobLauncher - No TaskExecutor has been set, defaulting to synchronous executor.
                          14:01:10.521 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'jobLauncher'
                          14:01:10.523 [main] DEBUG o.s.c.s.ClassPathXmlApplicationContext - Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [[email protected]e552]
                          14:01:10.523 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
                          14:01:10.532 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'jobRepository'
                          14:01:10.533 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Autowiring by type from bean name 'org.springframework.batch.core.launch.support.CommandLineJobRunner' via property 'jobRepository' to bean named 'jobRepository'
                          14:01:10.533 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'jobLauncher'
                          14:01:10.533 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Autowiring by type from bean name 'org.springframework.batch.core.launch.support.CommandLineJobRunner' via property 'launcher' to bean named 'jobLauncher'
                          14:01:10.547 [main] ERROR o.s.b.c.l.s.CommandLineJobRunner - Job Terminated in error: No bean named 'HelloWorldTasklet' is defined
                          org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'HelloWorldTasklet' is defined
                          	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:527) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
                          	at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1083) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
                          	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
                          	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
                          	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1075) ~[spring-context-3.0.5.RELEASE.jar:3.0.5.RELEASE]
                          	at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:339) [spring-batch-core-2.1.7.RELEASE.jar:na]
                          	at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574) [spring-batch-core-2.1.7.RELEASE.jar:na]
                          14:01:10.548 [main] INFO  o.s.c.s.ClassPathXmlApplicationContext - Closing org.springframework.context.support.ClassPathXmlApplicationContext@defa1a: startup date [Thu Jun 23 14:01:09 EDT 2011]; root of context hierarchy
                          14:01:10.548 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
                          14:01:10.548 [main] INFO  o.s.b.f.s.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1a9334: defining beans [transactionManager,jobRepository,jobLauncher]; root of factory hierarchy
                          I just need a simple working Spring Batch project...every place I turn, exponentially more errors.

                          Comment


                          • #14
                            Say I use this on the command line. I've done the following:

                            Code:
                            $ git clone git://github.com/acogoluegnes/Spring-Batch-Workshop.git
                            $ cd Spring-Batch-Workshop
                            $ cd hello-world-solution
                            $ mvn package
                            Which worked fine. And mvn test passes successfully, so I know something's working here.

                            How would I be able to take the HelloWorldTasklet.class, and all dependencies, and put them into an isolated folder where I can demonstrate usage of CommandLineJobRunner? If I need maven then I'll use it, but I'm trying to move this to a non-build-environment. In the end, this is all I wish to do and if I could do this without errors, I'd be able to figure out a lot more on my own.

                            Comment


                            • #15
                              ok, first, the README also says that the PDF file is in the "presentation" directory (in the very first sentence). This PDF file helps you understand the concepts, not really how to launch Java programs from the command line.

                              second, Java programs are always tricky to run from the command line :-)

                              the "mvn package" command should have created a hello-world-solution-1.0.0.jar file in "target". Copy this JAR in a working directory.

                              then, go back in the "hello-world-solution" directory and launch the following command: "mvn dependency:copy-dependencies". It copies all the dependencies you need in the "target/dependency" directory. Copy all these JAR files in the working directory.

                              Then go to the working directory and launch the following command: java -classpath "./*" org.springframework.batch.core.launch.support.Comm andLineJobRunner hello-world-job.xml helloWorldJob

                              you should see some logging output but also the "hello world".

                              Comment

                              Working...
                              X