WebSecurityConfig 설정을 하자 마자 오류가 나는 것이다
자꾸 rename 하라는 알림창이 뜸 ㅠㅠㅠㅠ
찾아보니 버전의 문제라구......
package com.sparta.springsecurity.config;
import org.springframework.boot.autoconfigure.security.servlet.PathRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity // 스프링 Security 지원을 가능하게 함
public class WebSecurityConfig {
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
// h2-console 사용 및 resources 접근 허용 설정
return (web) -> web.ignoring()
.requestMatchers(PathRequest.toH2Console())
.requestMatchers(PathRequest.toStaticResources().atCommonLocations());
}
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
// CSRF 설정
http.csrf().disable();
http.authorizeRequests()
.requestMatchers("/h2-console/**").permitAll()
.requestMatchers("/css/**").permitAll()
.requestMatchers("/js/**").permitAll()
.requestMatchers("/images/**").permitAll()
.requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
.anyRequest().authenticated();
// 로그인 사용
http.formLogin();
return http.build();
}
}
requestMatchers로 바꾸니 깔끔하게 문제해결!
버전차이의 문제가 꽤나 많은 것 같다ㅜㅜ
'코딩 공부' 카테고리의 다른 글
Security 회원가입 오류 (0) | 2023.05.04 |
---|---|
게시물 좋아요 삭제 오류 (1) | 2023.05.04 |
댓글조회 완료 후 게시글 삭제 오류 (0) | 2023.04.28 |
git bash_오류해결_![rejected] main->main(fetch first ) (1) | 2023.04.25 |
import 오류 (persistence) (0) | 2023.04.19 |