Page 1 of 2 12 LastLast
Results 1 to 10 of 15

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

  1. #1
    Join Date
    Mar 2009
    Location
    Sydney, Australia
    Posts
    6

    Default 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. #2
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    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.

  3. #3
    Join Date
    Mar 2009
    Location
    Sydney, Australia
    Posts
    6

    Default

    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

  4. #4
    Join Date
    Feb 2008
    Posts
    488

    Default

    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:".

  5. #5
    Join Date
    Mar 2009
    Location
    Sydney, Australia
    Posts
    6

    Default

    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?

  6. #6
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    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?

  7. #7
    Join Date
    Mar 2009
    Location
    Sydney, Australia
    Posts
    6

    Default

    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!

  8. #8
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    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).

  9. #9
    Join Date
    May 2009
    Posts
    7

    Default

    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?

  10. #10
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    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.

Tags for this Thread

Posting Permissions

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