์•ˆ๋…•ํ•˜์„ธ์š”, Spring Security์— ๊ด€ํ•œ ์˜ค๋Š˜์˜ ๋ธ”๋กœ๊ทธ ๊ธ€์—์„œ๋Š” Spring Security ์„ค์ • ์ค‘ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” ์ผ๋ฐ˜์ ์ธ ์˜ค๋ฅ˜์™€ ์ด๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์ด์•ผ๊ธฐํ•ด๋ณด๋ ค ํ•ฉ๋‹ˆ๋‹ค. ํŠนํžˆ, AntPathRequestMatcher์™€ MvcRequestMatcher์˜ ์‚ฌ์šฉ๊ณผ ๊ด€๋ จ๋œ UnsatisfiedDependencyException ์˜ค๋ฅ˜ ํ•ด๊ฒฐ์— ์ดˆ์ ์„ ๋งž์ถœ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์ƒํ™ฉ ์„ค๋ช…

Spring Security๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๊ณผ์ •์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ตฌ๋ฌธ์œผ๋กœ ๋ณด์•ˆ ์„ค์ •์„ ์ •์˜ํ–ˆ์Šต๋‹ˆ๋‹ค:

.authorizeHttpRequests(auth -> auth
    .requestMatchers("/login", "/user/register", ... ) // ์งง์€ ๋ฒ„์ „
    .permitAll()
)

์ด๋Ÿฌํ•œ ์„ค์ •์€ AntPathRequestMatcher ๋Œ€์‹  ์ง์ ‘ ๊ฒฝ๋กœ๋ฅผ ์ง€์ •ํ•˜๋Š” ๊ฐ„๊ฒฐํ•œ ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ด ๊ตฌ์„ฑ์„ ์ ์šฉํ•œ ํ›„, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

UnsatisfiedDependencyException: Error creating bean with name 'WebSecurityConfiguration': ...
... Factory method 'filterChain' threw exception with message: This method cannot decide ...

์˜ค๋ฅ˜์˜ ์›์ธ

์ด ์˜ค๋ฅ˜๋Š” Spring Security๊ฐ€ ์š”์ฒญ ๋งค์ฒ˜๋ฅผ ํ•ด์„ํ•˜๋Š” ๊ณผ์ •์—์„œ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. requestMatchers() ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ, Spring์€ ์ œ๊ณต๋œ ํŒจํ„ด์ด Spring MVC ํŒจํ„ด์ธ์ง€ ์•„๋‹ˆ๋ฉด ์ผ๋ฐ˜ Ant ์Šคํƒ€์ผ์˜ ํŒจํ„ด์ธ์ง€ ์ž๋™์œผ๋กœ ํŒ๋‹จํ•˜๊ธฐ ์–ด๋ ต์Šต๋‹ˆ๋‹ค. ์ด๋กœ ์ธํ•ด, MvcRequestMatcher๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ์—์„œ AntPathRequestMatcher๋ฅผ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋ฉด ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋ช…์‹œ์ ์œผ๋กœ AntPathRequestMatcher ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด:

.authorizeHttpRequests(auth -> auth
    .requestMatchers(new AntPathRequestMatcher("/login")).permitAll()
    .requestMatchers(new AntPathRequestMatcher("/user/register")).permitAll()
    // ์ถ”๊ฐ€ ๊ฒฝ๋กœ...
)

์ด ๋ฐฉ์‹์€ Spring Security์—๊ฒŒ ๋ช…ํ™•ํžˆ Ant ์Šคํƒ€์ผ์˜ ๊ฒฝ๋กœ ๋งค์นญ์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Œ์„ ์•Œ๋ฆฝ๋‹ˆ๋‹ค, ๋”ฐ๋ผ์„œ UnsatisfiedDependencyException ์˜ค๋ฅ˜๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฐธ๊ณ ์ž๋ฃŒ