spring | spring boot/오류 해결
spring security - Error creating bean with name 'springSecurityFilterChain'
socialcomputer
2022. 2. 20. 13:12
반응형
spring security 를 공부하고 있는데 다른 문제가 았는줄 알고 해결해보려고 했는데, Error creating bean with name 'springSecurityFilterChain' 에러가 사라지지 않았다.
에러의 자세한 내용은
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.IllegalStateException: Can't configure anyRequest after itself
그리고 코드는 이렇다. 스프링 시큐리티를 설정하는 클래스 이다. (config패키지 아래에 있어야 하고, WebSecurityConfigurerAdapter를 상속받아야 한다. )
package com.example.notice.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import lombok.AllArgsConstructor;
@AllArgsConstructor
@Configuration //configuration 에서 AllArgsConstructor가 빠져서 bean등록 오류가 생성됨 -> @AllArgs..추가
@EnableWebSecurity//스프링 시큐리티 필터가 필터체인에 등록이 됨
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.authorizeRequests()
.antMatchers("/user/**").authenticated()
.antMatchers("/mannager/**").access("hasRole('ROLE_ADMIN') or hasRole('ROLE_MANNAGER')")
.antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')")
.anyRequest().permitAll()
.and()
.formLogin()
.loginPage("/login");
//-지우기 super.configure(http);
}
}
@EnableWebSecurity 어노테이션을 걸면 스프링 시큐리티 필터가 필터체인에 등록이 되는데 이게 되지 않았었다.
그래서 @AllArgsConstructor 어노테이션을 붙였더니 또 다른 오류가 생겼다.
문제는 맨 아래 줄에 super.configure(http) 였다. 오류메세지로 계속 순환된다 해서 지워봤더니 해결됐다..
반응형