简体   繁体   English

Spring Security:配置错误

[英]Spring Security : configuration error

I am not able to solve this problem that I have XSD version above 4 then why there is still conflict? 我无法解决这个问题,我有4级以上的XSD版本,为什么还有冲突呢?

I am using Spring JARs and all of them have version 4 or above and still getting error. 我正在使用Spring JAR,它们都有版本4或更高版本,但仍然出错。

Following is XSD for spring-security.xml : 以下是spring-security.xml XSD:

<?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: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-4.1.xsd">
    <security:http auto-config="true">  <!-- ////this line holds error/////-->
        <security:intercept-url pattern="/"
            access="hasRole('ROLE_ADMIN')" />
        <security:form-login login-page="/login"
            default-target-url="/" authentication-failure-url="/loginerror" />
        <security:logout logout-success-url="/logout" />
        <security:csrf disabled="true" />
    </security:http>
    <security:authentication-manager>
        <security:authentication-provider>
            <security:user-service>
                <security:user name="admin" authorities="ROLE_ADMIN"
                    password="admin" />
            </security:user-service>
        </security:authentication-provider>
    </security:authentication-manager>
</beans> 

and following is the error: 以下是错误:

Multiple annotations found at this line: - Configuration problem: You cannot use a spring-security-2.0.xsd or spring-security-3.0.xsd schema with Spring Security 3.1. 在此行找到多个注释: - 配置问题:您不能在Spring Security 3.1中使用spring-security-2.0.xsd或spring-security-3.0.xsd架构。 Please update your schema declarations to the 3.1 schema. 请将架构声明更新为3.1架构。 Offending resource: file [C:/Documents and Settings/Administrator/My Documents/Google Drive/spring_workspace/spring security_demo/WebContent/WEB-INF/security-context.xml] - You cannot use a spring-security-2.0.xsd or spring-security-3.0.xsd schema with Spring Security 3.1. 违规资源:文件[C:/ Documents and Settings / Administrator / My Documents / Google Drive / spring_workspace / spring security_demo / WebContent / WEB-INF / security-context.xml] - 您不能使用spring-security-2.0.xsd或Spring Security 3.1的spring-security-3.0.xsd模式。 Please update your schema declarations to the 3.1 schema. 请将架构声明更新为3.1架构。

and this is my schema for dispatcher servlet: 这是我的调度程序servlet架构:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">

First I thought I have conflicts in my both mentioned .xsd files but now both ' .xsd' files have same schema. 首先,我认为我提到的.xsd文件中存在冲突,但现在两个'.xsd'文件都有相同的模式。

Edit: Event details 编辑:活动详情

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: You cannot use a spring-security-2.0.xsd or spring-security-3.0.xsd schema with Spring Security 3.1. org.springframework.beans.factory.parsing.BeanDefinitionParsingException:配置问题:您不能在Spring Security 3.1中使用spring-security-2.0.xsd或spring-security-3.0.xsd架构。 Please update your schema declarations to the 3.1 schema. 请将架构声明更新为3.1架构。 Offending resource: file [C:/Documents and Settings/Administrator/My Documents/Google Drive/spring_workspace/spring security_demo/WebContent/WEB-INF/security-context.xml] 违规资源:文件[C:/ Documents and Settings / Administrator / My Documents / Google Drive / spring_workspace / spring security_demo / WebContent / WEB-INF / security-context.xml]

at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$BeansConfigProblemReporter.fatal(BeansConfig.java:1137) 在org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig $ BeansConfigProblemReporter.fatal(BeansConfig.java:1137)

at org.springframework.beans.factory.parsing.ReaderContext.fatal(ReaderContext.java:68) 在org.springframework.beans.factory.parsing.ReaderContext.fatal(ReaderContext.java:68)

at org.springframework.beans.factory.parsing.ReaderContext.fatal(ReaderContext.java:55) 在org.springframework.beans.factory.parsing.ReaderContext.fatal(ReaderContext.java:55)

at org.springframework.security.config.SecurityNamespaceHandler.parse(SecurityNamespaceHandler.java:66) 在org.springframework.security.config.SecurityNamespaceHandler.parse(SecurityNamespaceHandler.java:66)

at org.springframework.ide.eclipse.beans.core.internal.model.namespaces.DelegatingNamespaceHandlerResolver$ElementTrackingNamespaceHandler.parse(DelegatingNamespaceHandlerResolver.java:177) at org.springframework.ide.eclipse.beans.core.internal.model.namespaces.DelegatingNamespaceHandlerResolver $ ElementTrackingNamespaceHandler.parse(DelegatingNamespaceHandlerResolver.java:177)

at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1411) 在org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1411)

at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$ErrorSuppressingBeanDefinitionParserDelegate.parseCustomElement(BeansConfig.java:1428) 在org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig $ ErrorSuppressingBeanDefinitionParserDelegate.parseCustomElement(BeansConfig.java:1428)

at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1401) 在org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1401)

at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:172) 在org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:172)

at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$ToolingFriendlyBeanDefinitionDocumentReader.doRegisterBeanDefinitions(BeansConfig.java:1357) 在org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig $ ToolingFriendlyBeanDefinitionDocumentReader.doRegisterBeanDefinitions(BeansConfig.java:1357)

at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:94) at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:94)

at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508) 在org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508)

at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$2.registerBeanDefinitions(BeansConfig.java:410) 在org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig $ 2.registerBeanDefinitions(BeansConfig.java:410)

How to solve that? 怎么解决?

Your exception says 你的例外说

You should not use 4.1 xsd,since your spring security version is 3.1 您不应该使用4.1 xsd,因为您的Spring安全版本是3.1

In below line you have mentioned spring security version as 4.1,it should be 3.1 在下面的行中你提到了弹簧安全版本为4.1,它应该是3.1

 http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.1.xsd">

Two ways to solve 两种解决方法

  1. Change to http://www.springframework.org/schema/security/spring-security-3.1.xsd 转到http://www.springframework.org/schema/security/spring-security-3.1.xsd
  2. Remove version so that spring will take automatically http://www.springframework.org/schema/security/spring-security.xsd 删除版本,以便春天将自动采取http://www.springframework.org/schema/security/spring-security.xsd

Update : Add use-expressions attribute to http .Since you are using expression hasRole('Role_Admin') you have to provide this. 更新:将use-expressions属性添加到http 。因为您正在使用表达式hasRole('Role_Admin')您必须提供此属性。

<security:http auto-config="true" use-expressions="true">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM