๐Ÿ“˜ Programming/โŒ ERR

java.lang.IllegalArgumentException: This method cannot decide whether these patterns are Spring MVC patterns or not ์—๋Ÿฌ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

ํ•œ์ฝ”๋”ฉ 2023. 11. 13. 21:54
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
๋ฐ˜์‘ํ˜•