找不到XML架构命名空间的Spring NamespaceHandler[http://www.springframework.org/schema/batch] 处境
我正在使用SpringBatch为我们的数据仓库构建一个累积快照,我有一个无法解决的配置障碍 我已经用STS(springsourcetoolsuite2.8.1)创建了一个简单的Spring批处理项目,它使用Spring模板项目。这是我创建的两个xml配置文件: 启动context.xml找不到XML架构命名空间的Spring NamespaceHandler[http://www.springframework.org/schema/batch] 处境,spring,spring-batch,Spring,Spring Batch,我正在使用SpringBatch为我们的数据仓库构建一个累积快照,我有一个无法解决的配置障碍 我已经用STS(springsourcetoolsuite2.8.1)创建了一个简单的Spring批处理项目,它使用Spring模板项目。这是我创建的两个xml配置文件: 启动context.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sprin
<?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" />
<?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>
因此,我不认为这是一个类路径问题,因为在控制台中,它似乎正在查找jar
我试过的
基于错误,我粘贴了以下URL
Spring批处理的名称空间地址似乎是正确的。我也没有发现任何有用的东西。我在某个地方读到“某物”可能会覆盖文件的名称空间,但并不真正理解为什么、什么和/或如何解决它
这只是开箱即用,在没有做任何修改、附加组件或任何事情的情况下已经无法工作。有什么想法吗
谢谢
解决方案
除了下面标记为正确的溶液之外。我还必须将launch-context.xml从组件扫描更改为常规spring连接,如下所示:
<!-- 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>
在运行时类路径上需要spring-batch.jar。它提供了一个能够处理该特定名称空间的名称空间处理程序。导致此错误的原因是spring-batch-core-2.1.7.RELEASE.jar中的META-INF/spring.handlers文件未被看到。此文件包含
http\://www.springframework.org/schema/batch=org.springframework.batch.core.configuration.xml.CoreNamespaceHandler
看起来要么是类路径问题,要么是其他JAR(例如spring上下文)中的spring.handlers文件以某种方式优先
通过CommandLineJobRunner:java-jar运行作业
batchprimer-1.0.jar META-INF/spring/module-context.xml job1
即使有一个完整的目标文件夹,您也必须为java命令提供类路径信息,为了简化配置,您可以使用一体式可执行jar(例如with)或可执行shell脚本(.bat/.sh)以及所有需要的库(例如with)
maven shade插件示例配置(创建额外的jar):
maven阴影插件
1.5
包裹
阴凉处
org.springframework.batch.core.launch.support.CommandLineJobRunner
META-INF/spring.handlers
META-INF/spring.schemas
真的
可执行
appassembler配置示例(创建子文件夹结构和.bat/.sh):
appassembler maven插件
org.codehaus.mojo
1.1.1
平的
假的
${project.build.directory}/appassembler
512M
1024米
-Dlog4j.configuration=../etc/log4j/log4j.properties
等
应用程序名
org.springframework.batch.core.launch.support.CommandLineJobRunner
spring/job-runner.xml
helloWorldJob
input.file.pattern=文件:…/***.txt
引导程序unix
引导窗口
包裹
生成守护进程
创建存储库
在我的例子中,它只是缺少spring事务依赖项——或者可能指向一个旧的依赖项。用3.1替换它可以消除错误。我使用的是spring批处理版本3.X.X和其他spring依赖项版本4.X.X,并收到了上述错误。经过一些尝试和错误,我发现维护所有类似的spring版本解决了我的问题。因此,建议您要么使用SpringBatch版本3.X.X,要么将SpringJDBC和SpringTX的SpringDependecy版本设置为2.X.X
关于Rave,我有spring-batch-core-2.1.7.RELEASE.jar、spring-batch-infrastructure-2.1.7.RELEASE.jar以及其他spring-XXX-3.0.6.RELEASE.jar和其他依赖项。我在目标文件夹中运行java-jar命令,目标文件夹中充满了类,还有一个lib文件夹,其中包含所有jar。清单文件有一个类路径条目,其值为:lib/spring-batch-core-2.1.7等。。我要把它加到我的博文谢谢,我如何控制顺序?@EmersonFarrugia:优先级不应该起任何作用:所有资源都被扫描,命名空间处理程序都被注册。@dma_k那么你知道我能做些什么吗?@Viriato:检查我在标题中的回复:首先确保你的根
MANIFEST.MF
是正确的。我认为Java只会META-INF/MANIFEST.MF
(而不是META-INF/spring/MANIFEST.MF
)——也许Java正在使用另一个清单文件。检查如何自定义清单文件。我还发现,这在某种程度上是相关的,但您使用的是最新的Spring版本,这种组合对我来说很有效。MANIFEST.MF一直在META-INF下面。对不起,我弄错了。如果我放弃,我会尽快更新帖子。如果您没有什么特别的,请将jar+libs上传到文件共享。我将尝试在调试器下运行它,断点位于DefaultNamespaceHandlerResolver#getHandlerMappings()
方法(顺便说一句,尝试增加日志级别以进行调试,并查看此类报告的内容;应该是什么样子)
<!-- 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>
http\://www.springframework.org/schema/batch=org.springframework.batch.core.configuration.xml.CoreNamespaceHandler
<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>
<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>