1

我已经通过 Eclipse 为 Spring 项目创建了一个可执行的 JAR。

它在我的系统上按预期工作,但是当我尝试在另一个系统上执行相同的 JAR 时,它不起作用。它抛出一个异常,如:

Exception-->
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from
 relative location [applicationContext-DAO.xml]
Offending resource: class path resource [resources/applicationContext.xml]; nested exception is org.springframework.beans.factory.xml.X
mlBeanDefinitionStoreException: Line 6 in XML document from class path resource [resources/applicationContext-DAO.xml] is invalid; nest
ed exception is org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 336; cvc-elt.1: Cannot find the declaration of element 'bea
ns'.
        at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
        at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
        at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinition
DocumentReader.java:271)
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentR
eader.java:196)
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocument
Reader.java:181)
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDoc
umentReader.java:140)
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocum
entReader.java:111)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
        at com.nextenders.server.ApplicationContext.initContextFile(ApplicationContext.java:88)
        at com.nextenders.server.ApplicationContext.<init>(ApplicationContext.java:60)
        at com.nextenders.server.ApplicationContext.getInstance(ApplicationContext.java:45)
        at com.nextenders.common.DaoReceiver.processRequest(DaoReceiver.java:49)
        at com.nextenders.common.DaoHandler.handleRequest(DaoHandler.java:12)
        at com.nextenders.facadeimplementation.facade.UtilityFacade.main(UtilityFacade.java:625)
Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 6 in XML document from class path resource [reso
urces/applicationContext-DAO.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 336; cvc-
elt.1: Cannot find the declaration of element 'beans'.
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinition
DocumentReader.java:255)
        ... 14 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 336; cvc-elt.1: Cannot find the declaration of element 'beans'.
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
        at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
        at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
        at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
        ... 17 more

C:\programforforkdocument>

我没有得到什么问题?我有一个疑问,比如它与路径有关吗?我的系统在执行时可能会获得正确的路径,因为它是从我的系统创建的吗?

更新:新错误:

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 9 in
 XML document from class path resource [resources/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.

我正在使用spring--3.2.0.RC2.jar和我的模式条目

<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-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">
4

3 回答 3

1

参考您的更新:请参阅此解决方案:

Create runnable jar with maven 3.1 using maven-dependency-plugin doesn't create runnable jar

The Problem seems to be with internal spring files which haven been overwritten in assembly phase. Which maven plugin do you use for assembly? Its seems that you have to use the maven-shade-plugin when building jars with spring framework which merges spring-handlers and spring-schemas. See solution of question.

于 2014-03-03T07:18:56.070 回答
0

在我看来,您可能缺少图书馆。我猜是里面有 spring-beans.dtd 文件的那个。

于 2013-05-09T11:15:04.870 回答
0

spring-beansjar 添加到类路径

于 2013-05-10T04:56:07.967 回答