未声明Spring安全性http和身份验证提供程序

hua*_*n68 1 spring spring-security

我试图将Spring安全性集成到我现有的项目中.我使用的工具是:

  1. 春天2.5.6.SEC03
  2. spring-security-core 3.1.1.RELEASE
  3. JDK 7.

在Spring配置中,我有这个:

<beans:beans xmlns="http://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-3.1.xsd
                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">

<http auto-config='true'>
  <intercept-url pattern="/messagePost.htm*" access="ROLE_USER"/>
</http>

<authentication-provider>
  <user-service>
    <user name="user1" password="1111" authorities="ROLE_USER"/>
  </user-service>
</authentication-provider>
</beans:beans>
Run Code Online (Sandbox Code Playgroud)

但是这个弹簧配置有一个错误:

  1. cvc-complex-type.2.4.c:匹配的通配符是strict,但是没有为元素'authentication-provider'找到声明.
  2. cvc-complex-type.2.4.c:匹配的通配符是strict,但是没有为元素'http'找到声明.

我可以知道如何解决这个问题吗?

sha*_*ltc 7

MaKe这些变化

<?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-3.1.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-3.1.xsd">

  <http auto-config='true'>
    <intercept-url pattern="/messagePost.htm*" access="ROLE_USER"/>
  </http>

  <authentication-manager>
    <authentication-provider>
      <user-service>
        <user name="user1" password="1111" authorities="ROLE_USER"/>
      </user-service>
    </authentication-provider>
  </authentication-manager>

</beans:beans>
Run Code Online (Sandbox Code Playgroud)

我做了以下更改

  1. 将xmlns架构更改"http://springframework.org/schema/security""http://www.springframework.org/schema/security"(添加了www:D)
  2. 我已将<authentication-provider>命名空间包含在命名<authentication-manager>空间中.