โ ExceptionHandler
- ์์ธ ์ฒ๋ฆฌ ํธ๋ค๋ฌ
- ํน์ ์์ธ๊ฐ ๋ฐ์ํ ์์ฒญ์ ์ฒ๋ฆฌํจ
- ์ง์ํ๋ ๋ฉ์๋ ์๊ท๋จผํธ๊ฐ ์ผ๋ฐ ํธ๋ค๋ฌ๋ณด๋ค๋ ํ์ ์ ์
- ์์ธ ๊ฐ์ฒด, ํธ๋ค๋ฌ ๊ฐ์ฒด, ๋ชจ๋ธ ๋ฑ (๊ณต์ ๋ฌธ์ ์ฐธ๊ณ )

๋ค๋ฅธ ํธ๋ค๋ฌ์์ TestException์ ๋์ง๋ฉด, testErrorHandler๊ฐ ๋์ํ๊ณ ์๋ฌ ํ์ด์ง๋ฅผ ๋ฐํ

- REST API์ ๊ฒฝ์ฐ ์ต์ ์ ํธ๋ค๋ฌ ๋ฆฌํด ํ์ ์ผ๋ก ResponseEntity๋ฅผ ์ฃผ๋ก ์ฌ์ฉํ๋ค.
โ ControllerAdvice
- ํน์ ์ปจํธ๋กค๋ฌ ์์์๊ฐ ์๋๋ผ, ๋ชจ๋ ์ปจํธ๋กค๋ฌ์ ๊ฑธ์ณ์ ExceptionHandler, InitBinder, ModelAttributes ๋ฅผ ์ ์ฉํ๊ณ ์ถ์ ๊ฒฝ์ฐ ์ฌ์ฉ

- @ContrllerAdvice ์์ฑ์ผ๋ก ์ ์ฉํ ๋ฒ์๋ฅผ ์ง์ ํ ์๋ ์๋ค.
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface ControllerAdvice {
@AliasFor("basePackages")
String[] value() default {};
@AliasFor("value")
String[] basePackages() default {};
Class<?>[] basePackageClasses() default {};
Class<?>[] assignableTypes() default {};
Class<? extends Annotation>[] annotations() default {};
}

'๊ฐ์ธ ๊ณต๋ถ > WEB' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
WAS (์น ์ ํ๋ฆฌ์ผ์ด์ ์๋ฒ) (0) | 2025.01.13 |
---|---|
Node.js๋ก node-red ๋ด์ฅ ์๋ฒ ๋์๋ณด๊ธฐ (0) | 2024.10.02 |
@SessionAttribute, @SessionAttriubtes (2) | 2024.03.01 |
@ModelAttribute (0) | 2024.03.01 |
[๊ฐ์ ์ ๋ฆฌ] ์คํ๋ง MVC ํ์ฉ (1) | 2024.02.29 |