Spring新手,现在想在SpringMVC的基础上使用Spring Security框架。但Spring Security配置报错,困扰了很久。先上代码
<?xml version="1.0" encoding="UTF-8"?>
<b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:b="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.1.xsd">
报错
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 9 in XML document from class path resource [config/spring-security.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 99; cvc-elt.1: 找不到元素 'b:beans' 的声明。
尝试网上的方法,加入
<!DOCTYPE b:beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
则报错
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 9 in XML document from class path resource [config/spring-security.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 99; 必须声明元素类型 "b:beans"。
请指教
<?xmlversion="1.0"encoding="UTF-8"?>
xmlns:security="http://www.springframework.org/schema/security"
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">
<security:httpauto-config='true'><curity:http><security:httpauto-config="true"use-expressions="false"access-denied-page="/login.jsp"><security:form-loginlogin-page="/login.jsp"authentication-failure-url="/login.jsp?error=true"authentication-success-handler-ref="loginSuccessHandler"always-use-default-target="true"/><security:logoutlogout-url="/logout"logout-success-url="/login.jsp"/><security:session-management><security:concurrency-controlmax-sessions="1"error-if-maximum-exceeded="false"expired-url="/login.jsp?error=islogin"><curity:concurrency-control><curity:session-management><security:intercept-urlpattern="rvices/**"access="IS_AUTHENTICATED_FULLY"><curity:intercept-url><security:intercept-urlpattern="/jsp/*.jsp"access="IS_AUTHENTICATED_FULLY"><curity:intercept-url><security:custom-filterref="myFilter"before="FILTER_SECURITY_INTERCEPTOR"/><curity:http><security:authentication-manageralias="authenticationManager"><security:authentication-provideruser-service-ref="myUserDetailService"><curity:authentication-provider><curity:authentication-manager><beanid="loginSuccessHandler"class="com.springsecurity.handler.LoginSuccessHandler"><propertyname="jdbcService"ref="jdbcService"/></bean><beanid="myFilter"class="com.springsecurity.filter.MyFilterSecurityInterceptor"><propertyname="authenticationManager"ref="authenticationManager"/><propertyname="accessDecisionManager"ref="myAccessDecisionManagerBean"/><propertyname="securityMetadataSource"ref="mySecurityMetadataSource"/></bean><beanid="myUserDetailService"class="com.springsecurity.handler.MyUserDetailService"><propertyname="userDao"ref="userDao"/><propertyname="jdbcService"ref="jdbcService"/></bean><beanid="myAccessDecisionManagerBean"class="com.springsecurity.filter.MyAccessDecisionManager"><propertyname="myInvocationSecurityMetadataSource"ref="mySecurityMetadataSource"/></bean><beanid="mySecurityMetadataSource"class="com.springsecurity.filter.MyInvocationSecurityMetadataSource"><constructor-arg><refbean="roleDao"/></constructor-arg></bean>
改成这种即可解决。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。