我们使用eclipse构建了一个spring-batch应用程序。每当我通过eclipse执行程序时,它运行正常。但是当我尝试生成并运行使用ant创建的jar文件时,我得到了这个难看的堆栈跟踪。
2012-Dec-27 11:10:30,880 1141 [main] [] ERROR (CommandLineJobRunner.java:355):作业终止错误:第12行 类路径资源[launch-context.xml]中的XML文档无效; 嵌套异常是org.xml.sax.SAXParseException:cvc-elt.1:不能 找到元素豆的声明'。 org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: 来自类路径资源[launch-context.xml]的XML文档中的第12行 是无效的;嵌套异常是org.xml.sax.SAXParseException: cvc-elt.1:无法找到元素' bean的声明。在 org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396) 在 org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334) 在 org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) 在 org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143) 在 org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178) 在 org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149) 在 org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212) 在 org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:126) 在 org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:92) 在 org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130) 在 org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467) 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397) 在 org.springframework.context.support.ClassPathXmlApplicationContext。(ClassPathXmlApplicationContext.java:139) 在 org.springframework.context.support.ClassPathXmlApplicationContext。(ClassPathXmlApplicationContext.java:83) 在 org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:282) 在 org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574) 在com.my.path.invoker.JobTest.main(JobTest.java:25)引起: org.xml.sax.SAXParseException:cvc-elt.1:找不到声明 元素豆类#39;在 com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195) 在 com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131) 在 com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384) 在 com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318) 在 com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1916) 在 com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:705) 在 com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400) 在 com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl $ NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:626) 在 com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl $ FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3103) 在 com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl $ PrologDriver.next(XMLDocumentScannerImpl.java:922) 在 com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648) 在 com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140) 在 com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511) 在 com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808) 在 com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737) 在 com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119) 在 com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:235) 在 com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284) 在 org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75) 在 org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388) ......还有16个
它基本上说在第11行它找不到元素bean的声明。这是我的发布背景。
<?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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>file:batch.properties</value>
<value>file:application.properties</value>
</list>
</property>
</bean>
<context:component-scan base-package="com.my.path" />
<import resource="classpath:/META-INF/spring/batch-context.xml" />
<import resource="classpath:/META-INF/spring/module-context.xml" />
</beans>
和我生成jar的build.xml。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create one in the same
directory with the processing instruction <?eclipse.ant.import?>
as the first entry and export the buildfile again. -->
<project basedir="." default="jar" name="ERS2Utilities">
<property environment="env"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
<path id="CLASSPATH">
<pathelement location="target/classes"/>
<pathelement location="target/test-classes"/>
<!--
<pathelement location="src/main/resources/lib/antlr-2.7.7.jar"/>
<pathelement location="src/main/resources/lib/antlr-runtime-3.2.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.instrument.tomcat-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.jms-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.js-2.1.1.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.web-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.web.portlet-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.web.servlet-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.web.struts-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.webflow-2.1.1.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/slf4j-api-1.6.1.jar"/>
<pathelement location="src/main/resources/lib/slf4j-api.jar"/>
<pathelement location="src/main/resources/lib/slf4j-log4j12-1.6.1.jar"/>
<pathelement location="src/main/resources/lib/commons-digester.jar"/>
-->
<pathelement location="src/main/resources/lib/com.springsource.org.aopalliance-1.0.0.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.aop-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.asm-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.aspects-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.beans-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.binding-2.1.1.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.context-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.context.support-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.core-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.expression-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.instrument-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.jdbc-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.orm-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.oxm-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.test-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/org.springframework.transaction-3.0.3.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/spring-batch-infrastructure-2.1.9.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/spring-batch-core-2.1.9.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/spring-batch-test-2.1.9.RELEASE.jar"/>
<pathelement location="src/main/resources/lib/commons-beanutils.jar"/>
<pathelement location="src/main/resources/lib/commons-collections-3.1.jar"/>
<pathelement location="src/main/resources/lib/commons-dbcp-1.4.jar"/>
<pathelement location="src/main/resources/lib/commons-lang-2.6.jar"/>
<pathelement location="src/main/resources/lib/commons-logging-1.1.1.jar"/>
<pathelement location="src/main/resources/lib/commons-pool-1.5.4.jar"/>
<pathelement location="src/main/resources/lib/junit-4.7.jar"/>
<pathelement location="src/main/resources/lib/ojdbc14.jar"/>
<pathelement location="src/main/resources/lib/log4j-1.2.16.jar"/>
<pathelement location="src/main/resources/lib/HashUtility.jar"/>
<pathelement location="src/main/resources/lib/commons-io-2.4.jar"/>
<pathelement location="src/main/resources/lib/mockito-all-1.9.5.jar"/>
</path>
<target name="init">
<mkdir dir="target/classes"/>
<mkdir dir="target/test-classes"/>
<copy includeemptydirs="false" todir="target/classes">
<fileset dir="src/main/resources">
<exclude name="**/*.java"/>
</fileset>
</copy>
<copy includeemptydirs="false" todir="target/classes">
<fileset dir="src/main/java">
<exclude name="**/*.java"/>
</fileset>
</copy>
<copy includeemptydirs="false" todir="target/test-classes">
<fileset dir="src/test/java">
<exclude name="**/*.java"/>
</fileset>
</copy>
<copy includeemptydirs="false" todir="target/classes">
<fileset dir="src/test/resources">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="target/classes"/>
<delete dir="target/test-classes"/>
</target>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="target/classes" source="${source}" target="${target}">
<src path="src/main/resources"/>
<classpath refid="CLASSPATH"/>
</javac>
<javac debug="true" debuglevel="${debuglevel}" destdir="target/classes" source="${source}" target="${target}">
<src path="src/main/java"/>
<classpath refid="CLASSPATH"/>
</javac>
<javac debug="true" debuglevel="${debuglevel}" destdir="target/test-classes" source="${source}" target="${target}">
<src path="src/test/java"/>
<classpath refid="CLASSPATH"/>
</javac>
<javac debug="true" debuglevel="${debuglevel}" destdir="target/classes" source="${source}" target="${target}">
<src path="src/test/resources"/>
<classpath refid="CLASSPATH"/>
</javac>
</target>
<!-- <target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<antcall target="build"/>
</target> -->
<target name="JobTest">
<java classname="com.my.path.invoker.JobTest" failonerror="true" fork="yes">
<arg line="launch-context.xml oiaExtractorJob"/>
<classpath refid="CLASSPATH"/>
</java>
</target>
<target name="jar" depends="build-project">
<copy todir="build/main" file="src/main/resources/log4j.xml"/>
<copy todir="build/main" file="application.properties"/>
<copy todir="build/main" file="batch.properties"/>
<copy todir="build/main" file="src/main/resources/ERSUtilities.sh"/>
<copy todir="build/main" file="src/main/resources/ERSUtilities.bat"/>
<jar destfile="build/main/ERS2SupportingUtilities.jar">
<fileset dir="target/classes"/>
<restrict>
<name name="**/*.class"/>
<archives>
<zips>
<fileset dir="./src/main/resources/lib" includes="**/*.jar"/>
</zips>
</archives>
</restrict>
<manifest>
<attribute name="Main-Class" value="com.my.path.invoker.JobTest"/>
<attribute name="Class-Path" value="./lib/log4j-1.2.16.jar
./lib/org.springframework.context-3.0.3RELEASE.jar
./lib/org.springframework.asm-3.0.3.RELEASE.jar
./lib/junit-4.7.jar
./lib/org.springframework.orm-3.0.3.RELEASE.jar
./lib/org.springframework.transaction-3.0.3.RELEASE.jar
./lib/org.springframework.aspects-3.0.3.RELEASE.jar
./lib/commons-pool-1.5.4.jar
./lib/org.springframework.core-3.0.3.RELEASE.jar
./lib/commons-logging-1.1.1.jar
./lib/HashUtility.jar
./lib/org.springframework.expression-3.0.3.RELEASE.jar
./lib/commons-lang-2.6.jar
./lib/org.springframework.instrument-3.0.3.RELEASE.jar
./lib/mockito-all-1.9.5.jar
./lib/com.springsource.org.aopalliance-1.0.0.jar
./lib/ojdbc14.jar
./lib/commons-io-2.4.jar
./lib/commons-collections-3.1.jar
./lib/org.springframework.jdbc-3.0.3.RELEASE.jar
./lib/spring-batch-infrastructure-2.1.9.RELEASE.jar
./lib/org.springframework.context.support-3.0.3.RELEASE.jar
./lib/commons-dbcp-1.4.jar
./lib/spring-batch-test-2.1.9.RELEASE.jar
./lib/org.springframework.beans-3.0.3.RELEASE.jar
./lib/org.springframework.oxm-3.0.3.RELEASE.jar
./lib/org.springframework.aop-3.0.3.RELEASE.jar
./lib/commons-beanutils.jar
./lib/org.springframework.binding-2.1.1.RELEASE.jar
./lib/spring-batch-core-2.1.9.RELEASE.jar
./lib/org.springframework.test-3.0.3.RELEASE.jar
./launch-context.xml
./log4j.xml"
/>
</manifest>
</jar>
</target>
</project>
我花了超过3天的时间没有用。我确保我正在制作的xsd引用与我正在使用的spring jar版本兼容。
非常感谢任何帮助。
同样的launch-context.xml在eclipse中工作,它在通过给定的ant build.xml构建时会抛出此错误。
我正在尝试将所有依赖的罐子包装成一个胖罐子。我发现几篇帖子表明我无法做到这一点。要参考打包的jar,我需要one-jar
或eclipse&#39; s jarinjarloader
。否则我将不得不在我的主罐子外面放置依赖的罐子。如果这是真正的问题,我会尝试这些选项并回来。同时,如果您对此编辑有任何意见,请更新您的答案,我会将其标记为正确。
答案 0 :(得分:0)
您选择的XML编辑器/验证器是否成功验证了您的应用程序上下文(您称之为启动上下文的那个)?它无效,因为http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
无效。
但是,你发布的内容(它只是一个摘录?)甚至不需要batch
命名空间。因此,您可以将其删除,从而将其转换为有效的XML。
答案 1 :(得分:0)
在ant脚本中,你对spring 3.0.3有一个依赖,在应用程序上下文中包含spring 3.0,可能是问题吗?
答案 2 :(得分:0)
如果你的执行服务器的防火墙阻止访问外部互联网(这通常是一件好事),那么你需要使用spring.handlers和spring.schemas来帮助应用程序解析你的上下文文件。
这将引用框架库中存在的模式,而不是试图从互联网中提取模式。
<强> /META-INF/spring.handlers 强>
http\://www.springframework.org/schema/batch=org.springframework.batch.core.configuration.xml.CoreNamespaceHandler
http\://www.springframework.org/schema/context=org.springframework.context.config.ContextNamespaceHandler
http\://www.springframework.org/schema/jdbc=org.springframework.jdbc.config.JdbcNamespaceHandler
<强> /META-INF/spring.schemas 强>
http\://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd
http\://www.springframework.org/schema/context/spring-context-3.0.xsd=org/springframework/context/config/spring-context-3.0.xsd
http\://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd=org/springframework/jdbc/config/spring-jdbc-3.0.xsd
http\://www.springframework.org/schema/batch/spring-batch-2.1.xsd=org/springframework/batch/core/configuration/xml/spring-batch-2.1.xsd