无法找到XML模式名称空间的Spring NamespaceHandler [http://www.springframework.org/schema/batch] [英] Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/batch]

查看:59
本文介绍了无法找到XML模式名称空间的Spring NamespaceHandler [http://www.springframework.org/schema/batch]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring Batch为我们的数据仓库构建一个累积快照,并且遇到了我无法弄清的配置障碍.

I am using Spring Batch to build an Accumulative Snapshot for our Data Warehouse and I am having a configuration roadblock that I cannot figure out.

我已经使用 Spring模板项目使用STS(SpringSource Tool Suite 2.8.1)创建了一个简单的Spring Batch项目.这些是我创建的两个xml配置文件:

I have created a Simple Spring Batch Project with STS (SpringSource Tool Suite 2.8.1) using the Spring Template Project. These were my two xml configuration files created:

launch-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="
    http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
    http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<context:property-placeholder location="classpath:batch.properties" />

<context:component-scan base-package="edu.kdc.visioncards" />

<jdbc:initialize-database data-source="dataSource">
    <jdbc:script location="${batch.schema.script}" />
</jdbc:initialize-database>

<batch:job-repository id="jobRepository" />

<import resource="classpath:/META-INF/spring/module-context.xml" />

module-context.xml

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch="http://www.springframework.org/schema/batch"
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<description>Example job to get you started. It provides a skeleton for a typical batch application.</description>

<batch:job id="job1">
    <batch:step id="step1"  >           
        <batch:tasklet transaction-manager="transactionManager" start-limit="100" >
            <batch:chunk reader="reader" writer="writer" commit-interval="1" />
        </batch:tasklet>
    </batch:step>
</batch:job> 

</beans>

问题

我运行以下命令来编译和打包项目: mvn clean compile install

然后我按如下操作:

  1. cd target 文件夹

通过CommandLineJobRunner运行作业: java -jar batchprimer-1.0.jar META-INF/spring/module-context.xml job1

Run the job through CommandLineJobRunner: java -jar batchprimer-1.0.jar META-INF/spring/module-context.xml job1

,我收到以下错误消息:

and I get the following error:

C:\stsworkspace\BatchPrimer\target>java -jar batchprimer-1.0.jar META-INF/spring
/module-context.xml job1
2011-12-15 12:03:53,421 INFO [org.springframework.context.support.ClassPathXmlAp
plicationContext] - <Refreshing org.springframework.context.support.ClassPathXml
ApplicationContext@84abc9: startup date [Thu Dec 15 12:03:53 EST 2011]; root of
context hierarchy>
2011-12-15 12:03:53,468 INFO [org.springframework.beans.factory.xml.XmlBeanDefin
itionReader] - <Loading XML bean definitions from class path resource [META-INF/
spring/module-context.xml]>
2011-12-15 12:03:53,796 ERROR [org.springframework.batch.core.launch.support.Com
mandLineJobRunner] - <Job Terminated in error: Configuration problem: Unable to
locate Spring NamespaceHandler for XML schema namespace [http://www.springframew
ork.org/schema/batch]
Offending resource: class path resource [META-INF/spring/module-context.xml]
>
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Config
uration problem: Unable to locate Spring NamespaceHandler for XML schema namespa
ce [http://www.springframework.org/schema/batch]
Offending resource: class path resource [META-INF/spring/module-context.xml]

        at org.springframework.beans.factory.parsing.FailFastProblemReporter.err
or(FailFastProblemReporter.java:68)
        at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderC
ontext.java:85)
        at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderC
ontext.java:80)
        at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.er
ror(BeanDefinitionParserDelegate.java:284)
        at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.pa
rseCustomElement(BeanDefinitionParserDelegate.java:1335)
        at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.pa
rseCustomElement(BeanDefinitionParserDelegate.java:1328)
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentRe
ader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentRe
ader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:93)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registe
rBeanDefinitions(XmlBeanDefinitionReader.java:493)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadB
eanDefinitions(XmlBeanDefinitionReader.java:390)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
nDefinitions(XmlBeanDefinitionReader.java:334)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
nDefinitions(XmlBeanDefinitionReader.java:302)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
        at org.springframework.context.support.AbstractXmlApplicationContext.loa
dBeanDefinitions(AbstractXmlApplicationContext.java:126)
        at org.springframework.context.support.AbstractXmlApplicationContext.loa
dBeanDefinitions(AbstractXmlApplicationContext.java:92)
        at org.springframework.context.support.AbstractRefreshableApplicationCon
text.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
        at org.springframework.context.support.AbstractApplicationContext.obtain
FreshBeanFactory(AbstractApplicationContext.java:467)
        at org.springframework.context.support.AbstractApplicationContext.refres
h(AbstractApplicationContext.java:397)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<i
nit>(ClassPathXmlApplicationContext.java:139)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<i
nit>(ClassPathXmlApplicationContext.java:83)
        at org.springframework.batch.core.launch.support.CommandLineJobRunner.st
art(CommandLineJobRunner.java:282)
        at org.springframework.batch.core.launch.support.CommandLineJobRunner.ma
in(CommandLineJobRunner.java:574)

其他内容

在用mvn install命令填充的目标文件夹中,我的操作如下:

Additional Stuff

In the target folder that got populated with the mvn install command I have as follows:

  1. 一个 classes 文件夹
  2. 一个包含我所有maven依赖项的 lib 文件夹
  3. 一个 maven-archiver 文件夹
  4. 一个测试类文件夹
  5. 一个 batchprimer-1.0.jar
  1. A classes folder
  2. a lib folder with all my maven dependencies
  3. a maven-archiver folder
  4. a test-classes folder
  5. a batchprimer-1.0.jar

在罐子内的 META-INF/MANIFEST.MF 中.我有以下内容:

Inside the jar, in the META-INF/MANIFEST.MF. I have as follows:

Manifest-Version: 1.0

Archiver-Version: Plexus Archiver

Created-By: Apache Maven

Built-By: dpardo

Build-Jdk: 1.6.0_20

Main-Class: org.springframework.batch.core.launch.support.CommandLineJ
 obRunner

Class-Path: lib/spring-jdbc-3.0.6.RELEASE.jar lib/spring-beans-3.0.6.R
 ELEASE.jar lib/spring-core-3.0.6.RELEASE.jar lib/spring-asm-3.0.6.REL
 EASE.jar lib/commons-logging-1.1.1.jar lib/spring-tx-3.0.6.RELEASE.ja
 r lib/aopalliance-1.0.jar lib/spring-aop-3.0.6.RELEASE.jar lib/spring
 -context-3.0.6.RELEASE.jar lib/spring-expression-3.0.6.RELEASE.jar li
 b/cglib-nodep-2.2.jar lib/spring-batch-core-2.1.7.RELEASE.jar lib/spr
 ing-batch-infrastructure-2.1.7.RELEASE.jar lib/xstream-1.3.jar lib/xp
 p3_min-1.1.4c.jar lib/jettison-1.1.jar lib/commons-io-1.4.jar lib/com
 mons-dbcp-1.2.2.jar lib/commons-pool-1.3.jar lib/hsqldb-1.8.0.7.jar l
 ib/aspectjrt-1.6.8.jar lib/aspectjweaver-1.6.8.jar lib/log4j-1.2.14.j
 ar lib/slf4j-log4j12-1.5.8.jar lib/slf4j-api-1.5.8.jar lib/mysql-conn
 ector-java-5.1.3.jar

所以我不认为这是类路径问题,因为在控制台中似乎正在找到jar.

So I do not think that it is a classpath issue because in the console it seems like it's finding the jars.

基于错误,我粘贴了以下URL

Based on the error, I pasted the following URL

http://www.springframework.org/schema/batch/

,Spring Batch的命名空间地址似乎是正确的.我也没有发现任何有用的东西.我在某处读到了某物".可能覆盖了文件的名称空间,但并没有真正理解为什么,什么和/或如何解决它.

and the address of the namespaces for Spring Batch seems to be correct. I have not found anything useful neither out there. I read somewhere that "something" could be overriding the namespaces of the files but did not really understand why, what, and/or how to solve it.

这是开箱即用的,如果不做任何修改,添加或任何其他操作,就无法正常工作.有什么想法吗?

This is just out the box and already not working without having done any modifications, add-ons or anything. Any ideas?

谢谢

除了下面标记为正确的解决方案.我还必须将launch-context.xml从组件扫描更改为常规的弹簧接线,如下所示:

In addition to the marked as correct solution below. I also had to change the launch-context.xml from component scanning to regular spring wiring like this below:

<!-- Commented this 
<context:property-placeholder location="classpath:batch.properties" />  


<jdbc:initialize-database data-source="dataSource">
    <jdbc:script location="${batch.schema.script}" />
</jdbc:initialize-database>
-->
<!-- Replace it with this below -->
<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>

推荐答案

通过CommandLineJobRunner运行作业:java -jar batchprimer-1.0.jar META-INF/spring/module-context.xml job1

Run the job through CommandLineJobRunner: java -jar batchprimer-1.0.jar META-INF/spring/module-context.xml job1

即使具有完整的目标文件夹,您也必须提供Java命令的类路径信息,要简化配置,您可以使用多合一可执行jar进行尝试,例如与 maven-shade-plugin 或可执行的外壳脚本(.bat/.sh)一起使用库,例如与 appassembler-maven-plugin

even with a complete target folder you have to provide the classpath information for the java command, to ease the configuration you can try it with an all-in-one executable jar e.g. with maven-shade-plugin or an executable shell script (.bat/.sh) with all needed libraries, e.g. with appassembler-maven-plugin

maven-shade-plugin示例配置(创建其他jar):

maven-shade-plugin example configuration (creates additional jar):

<plugin>
    <!-- create an all-in-one executable jar with maven-shade-plugin
         bound to phase:package 
         special handling for spring.handlers/spring.schemas files
         to prevent overwriting (maven-shade-plugin joins them to
         one file) 

         usage:
         cd to <project>/target
         java -jar hello-world-java-1.0-SNAPSHOT-executable.jar spring/batch/job/hello-world-job.xml helloWorldJob
         -->                     
    <artifactId>maven-shade-plugin</artifactId>
    <version>1.5</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>org.springframework.batch.core.launch.support.CommandLineJobRunner</mainClass>
                    </transformer>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                        <resource>META-INF/spring.handlers</resource>
                    </transformer>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                        <resource>META-INF/spring.schemas</resource>
                    </transformer>
                </transformers>
                <shadedArtifactAttached>true</shadedArtifactAttached>
                <!-- configures the suffix name for the executable jar
                     here it will be '<project.artifact>-<project.version>-executable.jar'-->
                <shadedClassifierName>executable</shadedClassifierName>
            </configuration>
        </execution>
    </executions>
</plugin>

示例appassembler配置(创建子文件夹结构和.bat/.sh):

example appassembler configuration (creates subfolder structure and .bat/.sh):

<plugin>
    <artifactId>appassembler-maven-plugin</artifactId>
    <groupId>org.codehaus.mojo</groupId>
    <version>1.1.1</version>
    <configuration>
        <repositoryLayout>flat</repositoryLayout>
        <installArtifacts>false</installArtifacts>
        <target>${project.build.directory}/appassembler</target>
        <defaultJvmSettings>
            <initialMemorySize>512M</initialMemorySize>
            <maxMemorySize>1024M</maxMemorySize>
            <extraArguments>
                <extraArgument>-Dlog4j.configuration=../etc/log4j/log4j.properties</extraArgument>
            </extraArguments>
        </defaultJvmSettings>
        <configurationDirectory>etc</configurationDirectory>
        <daemons>
            <daemon>
                <id>applicationName</id>
                <mainClass>org.springframework.batch.core.launch.support.CommandLineJobRunner</mainClass>
                <commandLineArguments>
                    <commandLineArgument>spring/job-runner.xml</commandLineArgument>
                    <commandLineArgument>helloWorldJob</commandLineArgument>
                    <commandLineArgument>input.file.pattern=file:.../**/*.txt</commandLineArgument>
                </commandLineArguments>
                <platforms>
                    <platform>booter-unix</platform>
                    <platform>booter-windows</platform>
                </platforms>
            </daemon>
        </daemons>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>generate-daemons</goal>
                <goal>create-repository</goal>
            </goals>
        </execution>
    </executions>
</plugin>

这篇关于无法找到XML模式名称空间的Spring NamespaceHandler [http://www.springframework.org/schema/batch]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆