Spring配置文件命名空间解析

时间:2014-03-30 13:35:39

标签: spring spring-mvc spring-security spring-bean

我的Spring bean配置文件中存在问题。我使用的是Spring Tool Suite 3.4和Spring 3.1.1 jar(MVC,jdbc,security)。这只是IDE中的警告,但是当应用程序加载到APP服务器时,它显示以下错误

Spring Configuration File - login-security.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:security="http://www.springframework.org/schema/security"
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.xsd">

<beans:import resource='login-service.xml'/> 
     <security:http> 
     <security:intercept-url pattern='/home*' access='ROLE_USER,ROLE_ADMIN' /> 
     <security:intercept-url pattern='/admin*' access='ROLE_ADMIN' /> 
     <security:form-login login-page='/login.jsp' default-target-url='/home' authentication-failure-url='/login.jsp?error=true'/> 
     <security:logout logout-success-url='/login.jsp' /> 
     <security:anonymous username='guest' granted-authority='ROLE_GUEST'/> 
     <security:remember-me/> 
</security:http>

 <security:authentication-manager> 
     <security:authentication-provider> 

       <security:jdbc-user-service data-source-ref='myDataSource' 
           users-by-username-query="select username, password, 'true' as enabled from USER_DETAILS where username=?"
           authorities-by-username-query="select USER_DETAILS.username , USER_AUTH.AUTHORITY as authorities from USER_DETAILS,USER_AUTH 
           where USER_DETAILS.username = ? AND USER_DETAILS.username=USER_AUTH.USERNAME"></security:jdbc-user-service>

     </security:authentication-provider>
   </security:authentication-manager>  

WARNING. ERROR IN CONSOLE - org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]
Offending resource: ServletContext resource [/WEB-INF/spring/appServlet/login-security.xml]

enter image description here

1 个答案:

答案 0 :(得分:0)

我认为你可能错过了pom中的spring security config依赖。

尝试将此添加到您的pom.xml

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-config</artifactId>
    <version>3.1.1.RELEASE</version>
</dependency>

希望这有帮助。