程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了cvc-elt.1:找不到元素'beans'的声明大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决cvc-elt.1:找不到元素'beans'的声明?

开发过程中遇到cvc-elt.1:找不到元素'beans'的声明的问题如何解决?下面主要结合日常开发的经验,给出你关于cvc-elt.1:找不到元素'beans'的声明的解决方法建议,希望对你解决cvc-elt.1:找不到元素'beans'的声明有所启发或帮助;

你的默认名称空间是,http://www.springframework.org/schema/security并且你配置了它,xmlns:beans="http://www.springframework.org/schema/beans"这意味着你必须将前缀添加beans:到所有标签形式,http://www.springframework.org/schema/beans因此你的XML应该如下所示。

<?xml version="1.0" enCoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
       xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/security
       http://www.springframework.org/schema/security/spring-security-3.2.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd"
       xmlns:context="http://www.springframework.org/schema/context">
    <context:component-scan base-package="com.humandevice.drive.fx">
        <context:include-filter type="regex"
                                Expression="com.humandevice.drive.fx.*" />
    </context:component-scan>
    <beans:bean ID="LoginController" alias="loginController" class="controller.LoginController">
        <beans:property name="authenticationManager" ref="authenticationManager" />
        <beans:property name="applicationContext" ref="applicationContext" />
    </beans:bean>
    <beans:bean ID="applicationContext" alias="applicationContext"
          class="org.springframework.context.ApplicationContext;">
    </beans:bean>
    <authentication-manager alias="authenticationManager">
        <authentication-provIDer user-service-ref="userService">
            <password-encoder ref="bCryptPasswordEncoder" />
        </authentication-provIDer>
    </authentication-manager>
</beans:beans>

解决方法

我正在尝试获取一个bean对象以使用Spring Security验证用户登录功能:

    ApplicationContext context = new ClassPathXmlApplicationContext(
            "com/humandevice/drive/fx/util/applicationContext.xml");
    authenticationManager = (AuthenticationManager) context
            .getBean("authenticationManager");

我applicationContext.xml的如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/security
       http://www.springframework.org/schema/security/spring-security-3.2.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd"
xmlns:context="http://www.springframework.org/schema/context">
<context:component-scan base-package="com.humandevice.drive.fx">
    <context:include-filter type="regex"
        expression="com.humandevice.drive.fx.*" />
</context:component-scan>
<bean id="LoginController" alias="loginController" class="controller.LoginController">
    <property name="authenticationManager" ref="authenticationManager" />
    <property name="applicationContext" ref="applicationContext" />
</bean>
<bean id="applicationContext" alias="applicationContext"
    class="org.springframework.context.ApplicationContext;">
</bean>
<authentication-manager alias="authenticationManager">
    <authentication-provider user-service-ref="userService">
        <password-encoder ref="bCryptPasswordEncoder" />
    </authentication-provider>
</authentication-manager>
 </beans>

但我得到这个异常:

Caused by: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 64; cvc-elt.1: Cannot find the declaration of element 'beans'.

我很难理解这个问题。

我对XML进行了如下更改:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd">

    <import resource="/context-service.xml" />
    <import resource="/context-repository.xml" />

    <context:component-scan base-package="com.humandevice.drive.fx"></context:component-scan>

    <authentication-manager>
        <authentication-provider user-service-ref="com.humandevice.drive.service.user.IUserService">
            <password-encoder ref="bCryptPasswordEncoder" />
        </authentication-provider>
    </authentication-manager>
</beans:beans>

我现在收到此异常:

lineNumber: 11; columnNumber: 44; cvc-complex-type.2.4.c: The matching wildcard is strict,but no declaration can be found for element 'import'.

大佬总结

以上是大佬教程为你收集整理的cvc-elt.1:找不到元素'beans'的声明全部内容,希望文章能够帮你解决cvc-elt.1:找不到元素'beans'的声明所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: