【问题标题】:Cannot find the declaration of element 'beans' inside SpringContext.xml在 SpringContext.xml 中找不到元素“beans”的声明
【发布时间】:2015-07-05 13:58:18
【问题描述】:

我正在从一个 java 类中调用一个 spring bean,并且正在从一个 scala 程序中调用那个 java 类。我已经使用 maven 将我的程序打包在一个 jar 中,并且正在爆炸其中的 spring 依赖项。但是当调用 bean 时,它会抛出下降异常-

> User class threw exception: Job aborted due to stage failure: Task 0
> in stage 5.0 failed 4 times, most recent failure: Lost task 0.3 in
> stage 5.0 (TID 6, hostname03):
> org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
> Line 6 in XML document from URL
> [jar:file:/hadoop/yarn/local/usercache/root/filecache/101/SomeJar-1.0-SNAPSHOT-job.jar!/SpringContext.xml]
> is invalid; nested exception is org.xml.sax.SAXParseException;
> lineNumber: 6; columnNumber: 122; 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)

我的 SpringContext.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:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <import resource="classpath:RuleSpringContext.xml" />
<bean id="serviceImpl" class="com.org.name.services.dao.ServiceImpl" /> 

    <bean id="contextInitializer" class="com.org.name.services.config.AppContextInitializer" />

</beans>

任何帮助将不胜感激。另外,当我从 eclipse bean 运行程序时,它会被调用,只是当我运行我的 jar 时,问题就来了。我正在使用 spark-submit 来运行 jar。

【问题讨论】:

    标签: java spring scala maven spring-mvc


    【解决方案1】:

    似乎 xml xsi:schemaLocation 声明错误。

    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-[version].xsd
    

    将 [version] 替换为您正在使用的相应 spring 版本。

    【讨论】:

    • 从 jar 文件中加载 Spring 模式,确保类路径中有正确的 jar,然后提取 spring-beans jar,您将在 beans/factory/xml 包下找到所有 xsd。
    • 是的,所有的 xsd 都在那里,我正在爆炸我的罐子。
    猜你喜欢
    • 2015-02-09
    • 2015-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-11
    • 2012-07-02
    • 2012-11-28
    • 2012-09-14
    相关资源
    最近更新 更多