728x90
728x90
์ํฉ
Caused by: java.lang.IllegalArgumentException: 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).
This is because there is more than one mappable servlet in your servlet context: {org.h2.server.web.JakartaWebServlet=[/h2-console/*], org.springframework.web.servlet.DispatcherServlet=[/]}.
requestMatchers ๋ถ๋ถ์์ ์๋ฌ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๋ญ๊ฐ ์๋ฉ ํ๋ ๋ฉ์์ง๋ก ์๋ฌ ๋ก๊ทธ๋ฅผ ๋ค์ฌ๋ค ๋ณด์์ต๋๋ค๋ง ์์ด๋ฅผ ์ ๋ชฐ๋ผ์์ธ๊ฐ ํ์ฐธ ๋ค์ฌ๋ค๋ณด๋ค ๊ฒจ์ฐ ์ฐพ์์ต๋๋ค.
์์ธ
๋ฌธ์ ์ฝ๋
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http
.authorizeRequests()
.requestMatchers("/login", "/signup", "/user").permitAll()
.anyRequest().authenticated()
.and()
...
}
์๋ฌ ๋ก๊ทธ๋ฅผ ๋ณด๋ ๊ฐ๊ณกํ ๋ถํํ๋ ๋ฉ์์ง๋ฅผ ์ฐพ์์ต๋๋ค.
please use requestMatchers(MvcRequestMatcher); otherwise, please use requestMatchers(AntPathRequestMatcher).
ํด๊ฒฐ
์์ ํ ์ฝ๋
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http
.authorizeRequests()
.requestMatchers(new AntPathRequestMatcher("/login"),
new AntPathRequestMatcher("/signup"),
new AntPathRequestMatcher("/user")).permitAll()
.anyRequest().authenticated()
.and()
...
}
AntPathRequestMatcher๋ก ๊ฐ์ธ์ฃผ๋ฉฐ ํ๋ ์๋ฌ๋ฅผ ์ ์ฌ์ ์ต๋๋ค.
728x90
๋ฐ์ํ