Notice
Recent Posts
Recent Comments
Link
반응형
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- 공동인증서
- 로그인
- docker
- 보안
- IntelliJ
- 허깅 페이스
- 컨퍼런스
- db
- NGINX
- 본인인증
- 코틀린
- PostgreSQL
- postgis
- 인증
- exception
- deepseek vs chatgpt
- Spring Boot
- netty
- AWS
- Flux
- Mono
- 본인확인
- 딥시크
- spring security
- API
- webflux
- ktlin
- Spring
- AOP
- Kotlin
Archives
- Today
- Total
[수미수의 개발 브로구]
[Spring] This method cannot decide whether these patterns are Spring MVC patterns or not. If this endpoint is a Spring MVC endpoint, please use requestMatchers(MvcRequestMatcher); otherwise, please use requestMatchers(AntPathRequestMatcher) 본문
Language & Framework/Spring
[Spring] This method cannot decide whether these patterns are Spring MVC patterns or not. If this endpoint is a Spring MVC endpoint, please use requestMatchers(MvcRequestMatcher); otherwise, please use requestMatchers(AntPathRequestMatcher)
수미수 2023. 11. 4. 20:58반응형
오류 내용
스프링 부트 3.1.4 와 스프링 시큐리티 6.1.4 기반의 프로젝트에서 스프링 시큐리티의 securityFilterChain 을 통해서 미인증 요청 URI 패턴을 등록 후 프로젝트를 시작 하니 아래와 같은 오류가 발생
This method cannot decide whether these patterns are Spring MVC patterns or not. If this endpoint is a Spring MVC endpoint, please use requestMatchers(MvcRequestMatcher); otherwise, please use requestMatchers(AntPathRequestMatcher)
해결 방안
스프링 시큐리티 버전으로 인해 해당 문제가 발생된것을 확인 하였고, securityFilterChain의 인증 미체크 패턴을 String 이 아닌 AntPathRequestMatcher 객체를 사용하여 해결 하였다.
변경 전 소스
@Bean
@Throws(Exception::class)
fun securityFilterChain(http: HttpSecurity): SecurityFilterChain? {
http.csrf { it.disable() }
.authorizeHttpRequests{ request ->
request.requestMatchers("/api/**")
.permitAll().anyRequest().authenticated()
}
.sessionManagement { manager ->
manager.sessionCreationPolicy(
STATELESS
)
}
return http.build()
}
변경 후 소스
@Bean
@Throws(Exception::class)
fun securityFilterChain(http: HttpSecurity): SecurityFilterChain? {
http.csrf { it.disable() }
.authorizeHttpRequests{ request ->
request.requestMatchers(
AntPathRequestMatcher("/"),
AntPathRequestMatcher("/css/**"),
AntPathRequestMatcher("/images/**"),
AntPathRequestMatcher("/js/**"),
AntPathRequestMatcher("/h2-console/**"),
AntPathRequestMatcher("/profile")
).permitAll().anyRequest().authenticated()
}
.sessionManagement { manager ->
manager.sessionCreationPolicy(
STATELESS
)
}
return http.build()
}
반응형