【发布时间】: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