인프런 커뮤니티 질문&답변
loginPage("/login").permitAll() 오류
작성
·
1.2K
0
안녕하세요
loginPage("/login").permitAll(); 라인중 permitAll() 추가할 경우 아래와같이 오류가 발생하는데요... 원인을 모르겠습니다.
무슨 문제때문인지 힌트를 얻을 수 있을까요?
java: 11
spring boot : 2.6.1
UserDetailsService userDetailsService;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests()
.anyRequest().authenticated();
http
.formLogin()
.loginPage("/login").permitAll();
http
.rememberMe()
.rememberMeParameter("remember")
.tokenValiditySeconds(3600)
.userDetailsService(userDetailsService);
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2021-12-05 15:36:54.966 ERROR 4156 --- [ main] o.s.boot.SpringApplication : Application run failed 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: permitAll only works with HttpSecurity.authorizeRequests() at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.13.jar:5.3.13] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486) ~[spring-beans-5.3.13.jar:5.3.13] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.13.jar:5.3.13]
답변 1
1
정수원
지식공유자
네
오류내용을 보면
permitAll only works with HttpSecurity.authorizeRequests() 이라고 되어 있습니다.
근데 작성하신 소스를 보면
http.authorizeHttpRequests() 로 시작하고 있습니다.
http.authorizeHttpRequests() 를 http.authorizeRequests() 로 변경하시면 정상 동작합니다.
그리고 확인해 보니 http.authorizeHttpRequests() 은 강의에서 사용하는 버전에서는 지원하지 않습니다.
스프링 시큐리티가 버전이 업그레이드 되면서 추가된 api 인것 같습니다.
참고하시기 바랍니다.





도움주셔서 감사합니다! :)