gpt4 book ai didi

java - 使用 @EnableWebSecurity 时,至少有一个非空 i..... 作为 @Bean。提示尝试扩展 WebSecurityConfigurerAdapter

转载 作者:太空宇宙 更新时间:2023-11-04 13:18:59 34 4
gpt4 key购买 nike

这是我花了几个小时尝试解决后无法弄清楚的问题。我正在研究带有java配置的spring security。我提出了以下异常,但不知道我应该做什么。

  Oct 22, 2015 6:00:57 AM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.servlet.Filter org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain() throws java.lang.Exception] threw exception; nested exception is java.lang.IllegalStateException: At least one non-null instance of WebSecurityConfigurer must be exposed as a @Bean when using @EnableWebSecurity. Hint try extending WebSecurityConfigurerAdapter

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.servlet.Filter org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain() throws java.lang.Exception] threw exception; nested exception is java.lang.IllegalStateException: At least one non-null instance of WebSecurityConfigurer must be exposed as a @Bean when using @EnableWebSecurity. Hint try extending WebSecurityConfigurerAdapter
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:188)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586)
... 33 more

Caused by: java.lang.IllegalStateException: At least one non-null instance of WebSecurityConfigurer must be exposed as a @Bean when using @EnableWebSecurity. Hint try extending WebSecurityConfigurerAdapter
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain(WebSecurityConfiguration.java:90)
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$1c09b217.CGLIB$springSecurityFilterChain$1(<generated>)
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$1c09b217$$FastClassBySpringCGLIB$$7b0370bc.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)

安全配置为

@Configuration
@EnableWebSecurity
public class AppSecurityConfiguration extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/allmessages*").hasAnyRole("USER", "ANONYMOUS")
.antMatchers("/postmessages*").hasRole("USER")
.antMatchers("/deletemessages*").hasRole("ADMIM")
.and()
.httpBasic();

}

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("tadtdab").password("tadtab").authorities("ROLE_ADMIN","ROLE_USER")
.and().withUser("tadi").password("tadi").authorities("ROLE_USER");
}
}

最佳答案

我遇到了同样的问题,读完这篇文章后我找到了答案:它在堆栈跟踪中:如果你转到消息的末尾,你可以找到这个:

Hint try extending WebSecurityConfigurerAdapter

所以我刚刚找到了我的 webSecurityConfig 类并添加了

extends WebSecurityConfigurerAdapter 

我的服务器正确启动

关于java - 使用 @EnableWebSecurity 时,至少有一个非空 i..... 作为 @Bean。提示尝试扩展 WebSecurityConfigurerAdapter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33278551/

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