gpt4 book ai didi

java - Spring 安全 : configuration error

转载 作者:搜寻专家 更新时间:2023-11-01 03:18:24 26 4
gpt4 key购买 nike

我无法解决这个问题,我的 XSD 版本高于 4 那么为什么仍然存在冲突?

我正在使用 Spring JAR,它们都具有版本 4 或更高版本,但仍然出现错误。

以下是 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>

错误如下:

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. Please update your schema declarations to the 3.1 schema. 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. Please update your schema declarations to the 3.1 schema.

这是我的调度程序 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">

首先,我认为我在提到的两个 .xsd 文件中存在冲突,但现在两个“.xsd”文件具有相同的架构。

编辑: Activity 详情

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. Please update your schema declarations to the 3.1 schema. Offending resource: file [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)

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

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

at 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.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1411)

at 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)

at 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)

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

at 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)

如何解决?

最佳答案

你的异常(exception)说

You should not use 4.1 xsd,since your spring security version is 3.1

下面这行你提到spring security版本是4.1,应该是3.1

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

两种解决方法

  1. 更改为 http://www.springframework.org/schema/security/spring-security-3.1.xsd
  2. 删除版本以便 spring 自动获取 http://www.springframework.org/schema/security/spring-security.xsd

更新:将 use-expressions 属性添加到 http。由于您正在使用表达式 hasRole('Role_Admin'),因此您必须提供此属性.

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

关于java - Spring 安全 : configuration error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39673737/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com