Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java cvc elt.1:找不到元素';豆子';_Java_Spring_Spring Security - Fatal编程技术网

Java cvc elt.1:找不到元素';豆子';

Java cvc elt.1:找不到元素';豆子';,java,spring,spring-security,Java,Spring,Spring Security,我正在尝试获取一个bean对象,以使用Spring Security验证用户登录功能: ApplicationContext context = new ClassPathXmlApplicationContext( "com/humandevice/drive/fx/util/applicationContext.xml"); authenticationManager = (AuthenticationManager) context

我正在尝试获取一个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>
我很难理解这个问题


更新

我对我的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>

我现在收到这个例外:


行号:11;栏目号:44;cvc complex type.2.4.c:匹配的通配符是严格的,但找不到元素“import”的声明。

您的默认命名空间是
http://www.springframework.org/schema/security
并且您配置了
xmlns:beans=”http://www.springframework.org/schema/beans"
这意味着您必须将前缀
bean:
添加到所有标签表单
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>

此代码将帮助您

<?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" 
xmlns:aop="http://www.springframework.org/schema/aop" 
xsi:schemaLocation="
http://www.springframework.org/schema/beans 
classpath:/org/springframework/beans/factory/xml/spring-beans-3.0.xsd 
http://www.springframework.org/schema/context 
classpath:/org/springframework/context/config/spring-context-3.0.xsd
http://www.springframework.org/schema/aop 
classpath:/org/springframework/aop/config/spring-aop-3.0.xsd
">      
</beans>


对于我来说,我只是在同一个地方剪切、粘贴和保存XML文件,这对我来说很有效

对我来说,对applicationContext.xml的更改没有在类路径中更新。因此,我手动从类路径中删除了applicationContext.xml文件,并重新构建了解决我问题的应用程序

我完全不确定为什么会出现这种行为。我也面临同样的例外,并遵循了
Karthikeyan Vaithilingam
的建议。但问题仍然没有解决。因此,我恢复了以前所做的更改并保存了文件。中提琴!!异常消失,现在没有错误。

我有类似的问题,我想再举一个可能原因的例子

xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="https://www.springframework.org/schema/mvc"
        xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:beans="https://www.springframework.org/schema/beans"
        xmlns:context="https://www.springframework.org/schema/context" xmlns:tx="https://www.springframework.org/schema/tx"
        xsi:schemaLocation="https://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd
            https://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
            https://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd
            https://www.springframework.org/schema/tx https://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

working.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"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-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/tx 
    http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

解决方案:

  • 使用
    xmlns=”http://www.springframework.org/schema/beans“
    作为基本xmlns。删除
    bean:
    前缀
  • https
    更改为
    http

  • 我用您的代码回复了我的代码,并删除了
    别名
    标记,因为它导致了错误,但现在我遇到了
    配置问题:无法找到XML架构命名空间的Spring NamespaceHandler[http://www.springframework.org/schema/security]
    您的类路径中是否有
    spring security config
    jar?我记得将它添加到pom.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"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xsi:schemaLocation="http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-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/tx 
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">