Announcement Announcement Module
Collapse
No announcement yet.
Namespace problems: "no declaration can be found for element 'job'" Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Namespace problems: "no declaration can be found for element 'job'"

    Hi,

    I'm using Spring Batch 2.0 RELEASE, and am getting these namespace errors even though I've already changed the schema to have spring batch as the default namespace, and set identical schema declarations in all of my spring configs.

    All my Spring configs have this declaration:

    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"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:util="http://www.springframework.org/schema/util"
    
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
         http://www.springframework.org/schema/batch  http://www.springframework.org/schema/batch/spring-batch-2.0.xsd
         http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
    In the 'topmost' config file, dailyExportApplicationContext.xml, i am importing 2 other spring configs, like so:

    Code:
    <beans:import resource="batchContext.xml"/>
    <beans:import resource="ftpContext.xml"/>
    But I keep getting these errors! (carriage returns added so it displays without scrollbars)

    Code:
    [XmlBeanDefinitionReader] Ignored XML validation warning
    org.xml.sax.SAXParseException: schema_reference.4: 
    Failed to read schema document 'http://www.springframework.org/schema/batch/spring-batch-2.0.xsd',  
    because 1) could not find the document; 2) the document could not be read; 
    3) the root element of the document is not <xsd:schema>.

    -- and further down the stacktrace, there is:

    Code:
    [CommandLineJobRunner] Job Terminated in error:
    org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: 
    Line 50 in XML document from class path resource [dailyExportApplicationContext.xml] is invalid; 
    nested exception is org.xml.sax.SAXParseException: 
    cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'job'. 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.
    doLoadBeanDefinitions(XmlBeanDefinitionReader.java:404)
    Line 50 in the xml document contains this declaration:

    Code:
        
    <job id="fullExport">
    		<step id="step1">
    			<tasklet ref="downloadTasklet" />
    		</step>
            <step id="step2">
                <tasklet ref="createExportFile" />
            </step>
    </job>

    Now I've checked my classpath and spring-batch-core-2.0.0.RELEASE.jar is definitely in it, so the schema should be found within this jar, right? I don't understand what else could be the problem. I've easily moved my project from 1.1.4 RELEASE to 2.0.0 RELEASE but I've hit a wall with this issue.

    Does anyone have an idea on what else could be causing this error or suggestions on how to resolve it?

    Strangely enough, even in IntelliJ IDEA I also get a little warning whenever I hover over the job element saying "Custom bean parsing is disabled for namespace 'http://www.springframework/schema/batch'", though that could be totally unrelated to my problem. (or is it? )

    Thanks everyone!

    Ellecer

  • #2
    Does every file have the schema definition you listed above? I'm just wondering if you assumed that the import was somewhat like linking in C, which it is not, they're still treated as separate files, that need separate namespace declarations, etc.

    Comment


    • #3
      Does every file have the schema definition you listed above?
      Yes. Each of the files mentioned in the post -

      dailyExportApplicationContext.xml
      batchContext.xml
      ftpContext.xml

      - have the same identical namespace declarations.

      However, I've just noticed that batchContext.xml actually imports another config file, referenceData.xml, and it has these declarations:

      Code:
      <beans xmlns="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:aop="http://www.springframework.org/schema/aop"
             xmlns:tx="http://www.springframework.org/schema/tx"
             xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
      So the hierarchy of the config files is:

      Code:
      dailyExportApplicationContext.xml
          --> batchContext.xml
               --> referenceData.xml
          --> ftpContext.xml
      where the "-->" refers to an import of another context file.

      So would this be the one causing the namespace issue? I'm a bit confused on whether the namespace declarations in a context file have any effect on the "parent" context file into which it ges imported. Do they?

      If the particular context file does *not* use any elements from spring-batch namespace at all ("http://www.springframework.org/schema/batch"), would it still need to have the same declaration as all the others?

      The only place where I actually use the spring-batch elements like <job> , <step> and <tasklet> is in dailyExportApplicationContext.xml

      Comment


      • #4
        You only need to declare the batch namespace when you actually use it. If you're not using it, it's an inconvenience to have it because you'll have to prefix everything with "beans:".

        Comment


        • #5
          Yes, that is pretty painful. I took your advice and have trimmed the xml configs, so only dailyExportApplicationContext.xml has the spring-batch namespace:

          Code:
          xmlns="http://www.springframework.org/schema/beans"
          xmlns:batch="http://www.springframework.org/schema/batch"
          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
          http://www.springframework.org/schema/batch  http://www.springframework.org/schema/batch/spring-batch-2.0.xsd">
          I've also made a change to batchContext.xml, since I want a MultiResourceItemReader to dynamically load resources, so I am setting it to scope="step":

          Code:
          <bean class="org.springframework.batch.core.scope.StepScope" />
          
          <bean id="multiResourceReader" class="org.springframework.batch.item.file.MultiResourceItemReader" scope="step">
            <property name="resources" value="file:///#{jobExecutionContext[ftp.output.directory]}/*.xml"/>
            <property name="delegate" ref="xmlFileReader"/>
          </bean>
          However, I am now getting a new error, still related to the namespace:

          Code:
          org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: 
          Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/batch]
          Offending resource: class path resource [dailyExportApplicationContext.xml]
          From my understanding, the namespace handler for the schema is supposed to be defined in META-INF/spring.handlers, and i've verified that the file exists inside the library spring-batch-core-2.0.0.RELEASE.jar

          Why would this error be happening in the first place? It doesn't make sense. I saw another post with the same problem - http://forum.springsource.org/showthread.php?p=233013 - but there wasn't a clear solution to that case.

          Any ideas?

          Comment


          • #6
            You are right: it doesn't make sense. Maybe Batch is not really on the classpath? Maybe there is an older version of the Batch jars on the classpath?

            Comment


            • #7
              No, on both questions. I saw that in the other forum post and ruled that out.

              If Spring batch wasn't on the classpath at all, then then nothing would work, right? I only got the error once I started trying to use the elements from spring batch namespace.

              And I don't think it's possible for Spring Batch 1.14 to be on the classpath. I am using maven to build and test this project, and I am copying the dependencies to a /lib directory, and then specifying this in the classpath when I build the jar:

              Code:
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-dependency-plugin</artifactId>
                  <executions>
                      <execution>
                          <id>copy-dependencies</id>
                          <phase>package</phase>
                          <goals>
                             <goal>copy-dependencies</goal>
                          </goals>
                          <configuration>
                           <outputDirectory>${project.build.directory}/lib</outputDirectory>
                          </configuration>
                       </execution>
                   </executions>
              </plugin>
              
              <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-jar-plugin</artifactId>
                      <configuration>
                                  <archive>
                                      <index>true</index>
                                      <manifest>
              <mainClass>org.springframework.batch.core.launch.support.CommandLineJobRunner</mainClass>
                                          <addClasspath>true</addClasspath>
                                          <classpathPrefix>lib/</classpathPrefix>
                                      </manifest>
                                  </archive>
                      </configuration>
              </plugin>
              and in the /lib directory, I only have spring-batch-*-2.0.0.RELEASE.jar files.

              I've given up on using the namespace altogether, as this has taken too much time already, so I've just used
              <bean class="org.springframework.batch.core.scope.StepSc ope" />


              so I could use scope="step" in defining my MultiResourceItemReader.

              (NOTE: IntelliJ flags this in red, but an existing bug exists for this, so this may get fixed by IDEA eventually)

              I've just changed the job to be defined using TaskletStep and SimpleJob explicitly defined as beans.

              The final config I've used is like this:

              Code:
              <bean id="taskletStep" abstract="true" class="org.springframework.batch.core.step.tasklet.TaskletStep">
                  <property name="jobRepository" ref="jobRepository"/>
                  <property name="transactionManager" ref="tm" />
              </bean>
              
              <bean id="uploadTasklet" class="org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter">
                <property name="targetObject" ref="ftpFileUploader"/>
                <property name="targetMethod" value="downloadFiles" />
              </bean>
              
              <bean id="uploadTasklet" class="org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter">
                <property name="targetObject" ref="ftpUploader"/>
                <property name="targetMethod" value="uploadFiles" />
              </bean>
              
              <bean id="archiveInputFileTasklet" class="org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter">
                <property name="targetObject" ref="archiveInputFile"/>
                <property name="targetMethod" value="archive" />
              </bean>
              
              <bean id="archiveOutputFileTasklet" class="org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter">
                <property name="targetObject" ref="archiveOutputFile"/>
                <property name="targetMethod" value="archive" />
              </bean>
              
              <bean id="fullExport" class="org.springframework.batch.core.job.SimpleJob">
                  <property name="jobRepository" ref="jobRepository"/>
                  <property name="steps">
                      <list>
                          <!-- download our input file -->
                          <!-- in afterStep method annotated with @AfterStep, we pass on the directory where the MultiResourceItemReader
                          picks up its resources to process -->
                          <bean parent="taskletStep" >
                             <!-- no need for TaskletAdapter because ftpFileDownloader implements Tasklet interface --> 
                             <!-- no need to add listener because ftpFileDownloader implements StepExecutionListener interface and taskletStep detects this-->
                             <property name="tasklet" ref="ftpFileDownloader"/>
                          </bean>
                          <!-- do the processing here. process all records in input files into output xml format, and spit em out in one file -->
                          <ref bean="createConvertedExport"/>
                          <!-- upload output file to external-facing ftp site -->
                          <bean parent="taskletStep" >
                             <property name="tasklet" ref="uploadTasklet"/>
                          </bean>
                          <!-- Gzip the file downloaded by ftpFileDownloader and move to archive directory -->
                          <bean parent="taskletStep">
                              <property name="tasklet" ref="archiveInputFileTasklet" />
                          </bean>
                          <!-- Gzip the file output of createConvertedExport and move to archive directory -->
                          <bean parent="taskletStep">
                              <property name="tasklet" ref="archiveOutputFileTasklet" />
                          </bean>                
                      </list>
                  </property>
              </bean>
              Anyway, all's working now. I'll try and have a go at using the namespace later on, once this is all feature-complete, but this'll do until then.

              Thanks for your responses lucas, DH and Dave!

              Comment


              • #8
                The example Maven config was useful, thank you. I get the same problem with running the jar but it's OK with "mvn exec:java", so it doesn't look like a Batch specific issue. I suspect a problem with the packaging plugin or with the JRE. I'll do some digging and try and find out (http://jira.springframework.org/browse/BATCH-1222).

                Comment


                • #9
                  I'm having the same problem here. Everything was alright until I changed from 1.1 to 2.0 and used the new namespace introduced in Spring 2.0.

                  When using new xml-tags or attributes Eclipse now complains that these elements are incorrect. The code-completion doesn't work either correctly.

                  e.g.:
                  Code:
                  <step id="myStep" parent="abstractMyStep">
                  	<tasklet>
                  		<chunk reader="myReader" />
                  	</tasklet>
                  </step>
                  Here Eclipse says, that chunk is not allowed as a subelement of tasklet.

                  Running my application as a Unit Test within eclipse, everything works fine, even if the xml's are red.

                  I tried to copy the spring-beans-2.0.xsd directly into the classpath and changed the xsi:schemaLocation into:

                  Code:
                  xsi:schemaLocation="http://www.springframework.org/schema/batch
                                      spring-batch-2.0.xsd"
                  Then Eclipse seems to use the right schema definition.

                  If I package now my application with mvn assembly:assembly, the jre complains about not finding the right schema, no matter which schemaLocation I use:

                  Code:
                  org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/batch/spring-batch2.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
                  If this is not a batch specific issue, you've got a workaround to better handle this issue?

                  Comment


                  • #10
                    If you are connected to the internet Eclipse will follow the http link to the schema definition, as long as you type it correctly. If not then you need to create a catalog entry for it (or otherwise hack like you did), or use the latest Spring IDE (comes with STS from http://www.springsource.com/products/sts) which has the catalog entry defined already, and also has some auto-completion features that you won't get fomr the raw XML editor. STS also knows the schema location so it can install it in your XML file with one mouse click. At runtime the parser pulls the XSD out of spring-batch-core JAR file, so you don't need to be online for that, and it's only the Eclipse editor you have to tweak.

                    Comment


                    • #11
                      Originally posted by Dave Syer View Post
                      If you are connected to the internet Eclipse will follow the http link to the schema definition, as long as you type it correctly.
                      It has to be correctly spelled because I'm able to follow this link in Eclipse by clicking ctrl+link. But obviously my Eclipse doesn't follow this link.

                      Anyway, here is my beans-definition:
                      Code:
                      <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/batch
                      		http://www.springframework.org/schema/batch/spring-batch-2.0.xsd 
                      		http://www.springframework.org/schema/beans
                      		http://www.springframework.org/schema/beans/spring-beans-2.0.xsd ">
                      Originally posted by Dave Syer View Post
                      or use the latest Spring IDE (comes with STS from http://www.springsource.com/products/sts) which has the catalog entry defined already
                      Thanks for this hint. Since I do have the spring extension installed already, I uninstalled it and installed the newest version again. Still the same problem: It seems to point to an old schema and marks all new elements red.

                      Originally posted by Dave Syer View Post
                      STS also knows the schema location so it can install it in your XML file with one mouse click.
                      How do I do this?

                      And how do I create extra catalog entries?

                      Thanks for your effort!

                      Comment


                      • #12
                        There is a version mismatch - there were some last minute changes to the Batch schema just before our release, and Spring IDE was released at about the same time. I looked and it seems the latest Spring IDE in STS doesn't have the Spring Batch 2.0.0.RELEASE jars. You can just replace the Batch jars in eclipse/plugins folder, but this should only affect the changes we made between RC3 and RELEASE, which are pretty minimal, so that wouldn't explain your schema validation failures.

                        You can create catalog entries in Eclipse using the XML editor preferences. Open up the preferences and type "catalog" in the filter. There's a post on this forum somewhere from Dan (DHGarrette) explaining the gorey details. But it shouldn't be necessary now.

                        The schema installation feature in Spring IDE should be automatically enabled for any Spring XMl file that you register with the Spring Beans Explorer. Just right click on the source text and choose "Configure Namespaces...".

                        Comment


                        • #13
                          Namespace handlers cannot be located in classpath with INDEX.LIST is used in jar

                          I ran into the same issue and found it had to do with generating an INDEX.LIST file in the jar. When generating the jar with the maven jar plugin, don't use the <index/> option. You can read the following for more information.

                          http://jira.springframework.org/browse/SPR-5705

                          Comment


                          • #14
                            Namespace problems: &quot;no declaration can be found for

                            I think I am very late in replying. I hope it helps those who reach this forum looking for an answer.

                            Please make sure you have this on top of your config file.


                            xsi:schemaLocation="http://www.springframework.org/schema/beans
                            http://www.springframework.org/schem...-beans-3.0.xsd
                            http://www.springframework.org/schema/batch
                            http://www.springframework.org/schema/batch/spring-batch-2.1.xsd"


                            Regards,
                            Rajesh K Ilango

                            Comment


                            • #15
                              I think this issue also happens if there is a problem in your internet connection. I was in the middle of some unit testing and I had not changed any of my sping batch configuration files. Then suddenly this error starting happening. I could not understand it, and then I realized that there was in temporary hiccup in my office internet. I tried again after 15 minutes and it worked fine.

                              Comment

                              Working...
                              X