-
카테고리
-
세부 분야
백엔드
-
해결 여부
미해결
2:00 에서 저처럼 버전 안 맞춰서 해서 헤매는 분들 이걸로 해보세요.
23.10.31 14:28 작성 23.11.08 11:39 수정 조회수 892
0
저처럼 버전 안 맞춰서 안되는 분들 이걸로 해결해보세요. 문서 참조해서 지원 중단된 방식은 제외하고 설정했습니다.
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
return httpSecurity
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests((registry) ->
registry.requestMatchers("/api/hello").permitAll()
.anyRequest().authenticated()
)
.build();
}
}
어노테이션에 꼭 @Configuration 이 들어가야 설정 파일로 인식해 제대로 작동합니다. 빼먹으시면 안됩니다.
답변을 작성해보세요.
0
junseong Kim
2023.11.26
terrinens 님 덕분에 해결했습니다. 감사합니다.
추가로 저는 spring 3.1.5 사용중인데 알려주신 코드대로 했을 때 requestMatchers()에서 Ant 패턴으로 작성하라는 컴파일 에러가 발생해서 아래와 같이 수정했습니다.
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
return httpSecurity
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests((registry) ->
registry.requestMatchers(new AntPathRequestMatcher("/api/hello")).permitAll()
.anyRequest().authenticated()
)
.build();
}
}
0
김태주
2023.10.31
@Bean
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
여기서 public에 밑줄이 그어져있는데 이유가 뭘까요?
답변 2