使用Maven配置Spring Batch

时间:2012-09-01 19:01:09

标签: spring spring-batch

使用Maven配置Spring Batch。 JDK使用:1.6,Spring Batch版本2.1.8.RELEASE; Spring版本3.0.5.RELEASE。获取运行时异常如下:

D:\SpringProject\SpringTry\target>java -jar SpringTry-1.0-SNAPSHOT.jar jobs/helloWorld.xml helloWorldJob
2012-09-02 00:23:51,650 INFO [org.springframework.context.support.ClassPathXmlApplicationContext] - <Refreshing org.springframework.context.
support.ClassPathXmlApplicationContext@b29c9d: startup date [Sun Sep 02 00:23:51 IST 2012]; root of context hierarchy>
2012-09-02 00:23:51,769 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from class path
 resource [jobs/helloWorld.xml]>
2012-09-02 00:23:53,854 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from class path
 resource [launch-context.xml]>
2012-09-02 00:23:53,929 ERROR [org.springframework.batch.core.launch.support.CommandLineJobRunner] - <Job Terminated in error: Configuration
 problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/batch]
Offending resource: class path resource [jobs/helloWorld.xml]
>
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler fo
r XML schema namespace [http://www.springframework.org/schema/batch]
Offending resource: class path resource [jobs/helloWorld.xml]

        at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
        at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)

有关如何解决此问题的任何建议。还注意到每次都会下载Spring 2.5.6以及3.0.5版本

我的清单看起来像:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Build-Jdk: 1.6.0
Main-Class: org.springframework.batch.core.launch.support.CommandLineJobRunner
Class-Path: lib/spring-batch-core-2.1.9.RELEASE.jar lib/xstream-1.3.jar lib/xpp3_min-1.1.4c.jar lib/jettison-1.1.jar lib/spring-aop-2.5.6.jar lib/aopalliance-1.0.jar lib/spring-tx-2.5.6.jar lib/spring-batch-infrastructure-2.1.9.RELEASE.jar lib/spring-beans-3.0.5.RELEASE.jar lib/spring-context-3.0.5.RELEASE.jar lib/spring-expression-3.0.5.RELEASE.jar lib/spring-asm-3.0.5.RELEASE.jar lib/spring-core-3.0.5.RELEASE.jar lib/commons-logging-1.1.1.jar lib/spring-jdbc-3.0.5.RELEASE.jar lib/log4j-1.2.16.jar lib/maven-resources-plugin-2.4.3.jar lib/maven-plugin-api-2.0.6.jar lib/maven-project-2.0.6.jar lib/maven-profile-2.0.6.jar lib/maven-artifact-manager-2.0.6.jar lib/maven-plugin-registry-2.0.6.jar lib/maven-core-2.0.6.jar lib/wagon-file-1.0-beta-2.jar lib/maven-plugin-parameter-documenter-2.0.6.jar lib/wagon-http-lightweight-1.0-beta-2.jar lib/wagon-http-shared-1.0-beta-2.jar lib/jtidy-4aug2000r7-dev.jar lib/xml-apis-1.0.b2.jar lib/maven-reporting-api-2.0.6.jar lib/doxia-sink-api-1.0-alpha-7.jar lib/wagon-provider-api-1.0-beta-2.jar lib/maven-repository-metadata-2.0.6.jar lib/maven-error-diagnostics-2.0.6.jar lib/commons-cli-1.0.jar lib/wagon-ssh-external-1.0-beta-2.jar lib/wagon-ssh-common-1.0-beta-2.jar lib/maven-plugin-descriptor-2.0.6.jar lib/plexus-interactivity-api-1.0-alpha-4.jar lib/wagon-ssh-1.0-beta-2.jar lib/jsch-0.1.27.jar lib/classworlds-1.1.jar lib/maven-artifact-2.0.6.jar lib/maven-settings-2.0.6.jar lib/maven-model-2.0.6.jar lib/maven-monitor-2.0.6.jar lib/plexus-container-default-1.0-alpha-9-stable-1.jar lib/junit-3.8.1.jar lib/plexus-utils-2.0.5.jar lib/maven-filtering-1.0-beta-4.jar lib/plexus-build-api-0.0.4.jar lib/plexus-interpolation-1.13.jar

2 个答案:

答案 0 :(得分:0)

很可能你是:

  • 只使用版本低于2.0的spring-batch-core jar(Maven依赖)版本。架构命名适用于2.0及更高版本。如果是这种情况,请更新您的依赖

  • 你的项目的pom.xml中有一个正确的(高于2.0)版本的spring-batch-core,但你也有一个传递依赖,它为你的项目带来了一个早期版本的spring-batch-core 。如果是这种情况,请尝试以下方法:

      

    mvn依赖:tree -Dverbose -Dincludes = org.springframework.batch

这将列出引入其自己版本的spring-batch依赖项的所有依赖项。在spring-batch-core上为这些依赖项添加一个排除条目,如下所示:

<dependency>
          <groupId>whatever.group</groupId>
          <artifactId>whateverArtifact</artifactId>
          <version>1.0</version>
          <exclusions>
            <exclusion>
                <groupId>org.springframework.batch</groupId>
                <artifactId>spring-batch-core</artifactId>
            </exclusion>
          </exclusions>
        </dependency>

答案 1 :(得分:0)

通过添加maven-shade-plugin解决了我的问题,具体如下: https://stackoverflow.com/a/8574629/1419116