【问题标题】:At least one non-null i..... as a @Bean when using @EnableWebSecurity. Hint try extending WebSecurityConfigurerAdapter使用@EnableWebSecurity 时,至少有一个非空i.....作为@Bean。提示尝试扩展 WebSecurityConfigurerAdapter
【发布时间】:2015-10-22 10:11:48
【问题描述】:

这是我花了几个小时尝试解决它后无法弄清楚的。我正在研究使用 java 配置的 spring 安全性。我想出了以下异常,但不知道我应该做什么。

  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");
    }
}

【问题讨论】:

    标签: java spring-mvc spring-security


    【解决方案1】:

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

    Hint try extending WebSecurityConfigurerAdapter
    

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

    extends WebSecurityConfigurerAdapter 
    

    而且我的服务器正常启动

    【讨论】:

      猜你喜欢
      • 2015-06-21
      • 2017-07-27
      • 2019-06-14
      • 2022-01-13
      • 2021-12-07
      • 1970-01-01
      • 2016-11-03
      • 2021-01-30
      相关资源
      最近更新 更多