java cvc-complex-type.2.4.a:发现以元素“bean”开头的无效内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25748048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 08:37:03  来源:igfitidea点击:

cvc-complex-type.2.4.a:Invalid content was found starting with element 'bean'

javaspringxsd

提问by agiledevpro

I've tried solving this issue for hours. When I run my code I get an error saying:

我已经尝试解决这个问题好几个小时了。当我运行我的代码时,我收到一条错误消息:

cvc-complex-type.2.4.a:Invalid content was found starting with element 'bean' One of '{"http://www.springframework.org/schema/context":include-filter, "http://www.springframework.org/schema/context":exclude-filter}' is expected.

cvc-complex-type.2.4.a:发现以元素'bean'开头的无效内容'{" http://www.springframework.org/schema/context":include-filter, " http://www 之一.springframework.org/schema/context":exclude-filter}' 是预期的。

I've looked around alot for answers, some suggestions were that one should make sure the right versions are used. I use the same version in my xml as in my pom file. (I'm using maven with eclipse btw).

我四处寻找答案,有些建议是应该确保使用正确的版本。我在 xml 中使用与 pom 文件中相同的版本。(顺便说一句,我在 Eclipse 中使用了 Maven)。

Any suggestions on what the problem might be?

关于问题可能是什么的任何建议?

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://www.springframework.org/schema/beans" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.2.7.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.2.7.xsd">
    <context:component-scan base-package="org.mywebbapp.filemanagement">

    <bean
        class="org.springframework.beans.factory.config.ServiceLocatorFactoryBean"
        id="FileStoreFactory">
        <property name="FileStore"
            value="org.mywebbapp.filemanagement.FileStoreFactory">
        </property>
    </bean>
    <alias alias="FH" name="FileHandler" />
</context:component-scan>
</beans>

回答by samlewis

<context:component-scan>should not have <bean>elements nested within.

<context:component-scan>不应<bean>嵌套元素。

Try:

尝试:

<context:component-scan base-package="org.mywebbapp.filemanagement"/>

<bean class="org.springframework.beans.factory.config.ServiceLocatorFactoryBean"
    id="FileStoreFactory">
    <property name="FileStore"
        value="org.mywebbapp.filemanagement.FileStoreFactory">
    </property>
</bean>
<alias alias="FH" name="FileHandler" />