开发者社区> 问答> 正文

配置Spring-Security报错,找不到元素 'b:beans&#?报错

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"。

请指教

展开
收起
爱吃鱼的程序员 2020-06-23 14:53:41 472 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    <?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>

    改成这种即可解决。

    2020-06-23 14:54:00
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载

相关实验场景

更多