์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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
- ๋ถํธ์บ ํ
- ๋ฐ์ผ๋ฆฌ์ฝ๋ฉ
- ๊ฑฐ๋ญ์ ๊ณฑ
- CLI๋ช ๋ น์ด
- ๋ฌธ์์ด๋ค์ง๊ธฐ
- Publishing
- ์ธํ ๋ฆฌ์ ์ด
- ๊นํ๋ธ
- ์คํ๋ง
- ๋ฐฑ์ค์๊ณ ๋ฆฌ์ฆ
- ๋ฐฑ์๋
- spring data jpa
- ์ฒซ๊ธ์๋๋ฌธ์
- ์ ๋ค๋ฆญ์ค
- ํ๊ณ
- ์๋ฃ๊ตฌ์กฐ
- ํ์ดํ๋ก๊ทธ๋๋ฐ
- ๊ณ์ฐ๊ธฐ๋ง๋ค๊ธฐ
- fibonacci
- ์๊ณ ๋ฆฌ์ฆ
- ์๋ฐ
- Spring Security
- Spring Data JDBC
- ๊ทธ๋ฆฌ๋
- ์ปฌ๋ ์ ํ๋ ์์ํฌ
- testing
- FilterChain
- HTML
- CSS
- java
Archives
- Today
- Total
๋์ ๋ชจ์
044 | Exception Handling in Spring MVC ๋ณธ๋ฌธ
๐ @ExceptionHandler๋ฅผ ์ด์ฉํ ์์ธ ์ฒ๋ฆฌ
- Controller ํด๋์ค ๋ ๋ฒจ์์ @ExceptionHandler๋ฅผ ์ฌ์ฉํ๋ฉด ํด๋น Controller์์ ๋ฐ์ํ๋ ์์ธ๋ฅผ ์ฒ๋ฆฌํ ์ ์๋ค.
- ํ์ํ ์์ธ ์ ๋ณด๋ง ๋ด์ ์ ์๋ Error ์ ์ฉ Response ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ๋ฉด ํด๋ผ์ด์ธํธ์๊ฒ ์กฐ๊ธ ๋ ์น์ ํ ์๋ฌ ์ ๋ณด๋ฅผ ์ ๊ณตํ ์ ์๋ค.
- BUT!
@ExceptionHandler ๋ฐฉ์์ Controller๋ง๋ค ๋์ผํ๊ฒ ๋ฐ์ํ๋ ์์ธ ์ฒ๋ฆฌ์ ๋ํ ์ค๋ณต ์ฝ๋๊ฐ ๋ฐ์ํ ์ ์๊ธฐ ๋๋ฌธ์ ๋ค์ํ ์ ํ์ ์์ธ๋ฅผ ์ฒ๋ฆฌํ๊ธฐ์๋ ์ ์ ํ์ง ์๋ค.
โ Ref.
- @ExceptionHandler
- BindingResult ํด๋์ค
- ConstraintViolation ์ธํฐํ์ด์ค & ๊ตฌํํด๋์ค
๐ @RestControllerAdvice๋ฅผ ์ด์ฉํ ์์ธ์ฒ๋ฆฌ
- @RestControllerAdvice๋ฅผ ์ถ๊ฐํ ํด๋์ค๋ฅผ ์ด์ฉํ๋ฉด ์์ธ ์ฒ๋ฆฌ๋ฅผ ๊ณตํตํ ํ ์ ์๋ค.
- @RestControllerAdvice๋ฅผ ์ฌ์ฉํ๋ฉด JSON ํ์์ ๋ฐ์ดํฐ๋ฅผ Response Body๋ก ์ ์กํ๊ธฐ ์ํด ResponseEntity๋ก ๋ํํ ํ์๊ฐ ์๋ค.
- @ResponseStatus๋ก HTTP Status๋ฅผ ๋์ ํํํ ์ ์๋ค.
โ Ref.
- @RestControllerAdvice
- Controller Advice
'SEB > TIL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
046 | Spring Data JDBC (0) | 2022.08.26 |
---|---|
045 | Checked / Unchecked / Customised Exception (0) | 2022.08.25 |
043 | Layer interconnect & Class Mapping (0) | 2022.08.23 |
042 | DTO ์ ํจ์ฑ ๊ฒ์ฆ (0) | 2022.08.23 |
042 | DTO with HTTP Request & Response (0) | 2022.08.22 |
Comments