gpt4 book ai didi

java - 基本的 Spring 安全错误

转载 作者:行者123 更新时间:2023-12-02 02:54:16 25 4
gpt4 key购买 nike

我有一个 Spring 应用程序,我要做的就是向其中添加 Spring Security 提供的所有默认 header 。我的web.xml更改如下:

<!-- Loads Spring Security config file -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-security.xml
</param-value>
</context-param>

<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>

<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

我的spring-security.xml如下:

<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="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-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd">

<http auto-config="true">
<headers />
</http>

</beans:beans>

我在启动时看到以下错误

引起:org.springframework.beans.factory.BeanCreationException:创建名称为“org.springframework.security.web.DefaultSecurityFilterChain#0”的bean时出错:无法解析对bean“org.springframework.security.web.authentication”的引用.UsernamePasswordAuthenticationFilter#0' 同时使用键 [4] 设置构造函数参数;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为“org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0”的bean时出错:无法解析对bean“org.springframework.security.authentication.ProviderManager#”的引用0'同时设置bean属性'authenticationManager';嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为“org.springframework.security.authentication.ProviderManager#0”的bean时出错:无法解析对bean“org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#”的引用0' 同时设置构造函数参数;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为“org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0”的 bean 时出错:FactoryBean 在对象创建时抛出异常;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:未定义名为“org.springframework.security.authenticationManager”的 bean:您是否忘记向配置中添加一个 gobal 元素(带有子元素)?或者,您可以在 和 元素上使用authentication-manager-ref 属性。

最佳答案

您需要给它一些东西来验证用户身份。尝试添加

<user-service>
<user name="user" password="password" authorities="ROLE_USER" />
</user-service>

到您的安全 xml 并查看示例 here.

关于java - 基本的 Spring 安全错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43358900/

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