Spring Annotation - hyunwoo-e/Spring GitHub Wiki
Annotation
- ์คํ๋ง์ classpath scanning์ ํตํด ์คํ
๋ ์คํ์
์ ํด๋์ค๋ค์ ํ์ง, ์๋์ ์ผ๋ก ํ๋ณด ์ปดํฌ๋ํธ๋ค์ ๋ฑ๋กํ๋ค.
- ๊ธฐ๋ณธ์ ์ผ๋ก @Component, @Repository, @Service, @Controller์ ํด๋์ค๋ค๋ง ํ๋ณด ์ปดํฌ๋ํธ๋ก ํ์ง๋๋ค.
- component-scan ์์์ include-filter๋ exclude-filter๋ฅผ ์ถ๊ฐํ์ฌ ํํฐ๋ฅผ ์ปค์คํฐ๋ง์ด์ง ํ๋ค.
@Component
- ์คํ๋ง์ด ๊ด๋ฆฌํ๋ ์ปดํฌ๋ํธ๋ฅผ ๋ํ๋ด๋ ์ผ๋ฐ์ ์ธ ์คํ
๋ ์ค ํ์
- ์ ์ฆ์ผ์ด์ค์ ์ํด ๊ตฌ์ฒดํ๋ ํํ๋ ์๋์ ๊ฐ๋ค.
- Repository - DAO์ ์ ์ฉ, DB Exception Translation ๊ธฐ๋ฅ, ์์์ฑ์ ๊ฐ์ง๋ ์์ฑ(DB,File)
- Service - ๋น์ฆ๋์ค ๋ก์ง
- Controller - MVC ์ปจํธ๋กค๋ฌ์์ ๋ช
์ Spring MVC
- RestContoller - REST ์ปจํธ๋กค๋ฌ์์ ๋ช
์ Spring REST
- ๊ฐ๋ฐ์๊ฐ ์ง์ ์์ฑํ Class์ ๊ฒฝ์ฐ @Component ์ฌ์ฉ(@Bean ์ ์ธ ๋ถ๊ฐ๋ฅ)
- @Component๋ ์ ์ธ๋ ํด๋์ค๋ฅผ Bean์ผ๋ก ๋ฑ๋ก
@Bean
- ๊ฐ๋ฐ์๊ฐ ์ปจํธ๋กค ๋ถ๊ฐ๋ฅํ ์ธ๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค์ Bean์ผ๋ก ๋ฑ๋กํ ๋ ์ฌ์ฉ
- @Bean์ ๋ฐํํ๋ ๊ฐ์ฒด๋ฅผ Bean์ผ๋ก ๋ฑ๋ก
@RequestMapping
- HTTP ์์ฒญ์ specificํ Handler ํด๋์ค๋ ๋ฉ์๋๋ฅผ ๋งคํ
@RequestBody
- Spring MVC์์ ํด๋ผ์ด์ธํธ์์ ์ ์กํ JSON/XML ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ฒด๋ก ๋ณํํด์ ๋ฐ์ ์ ์๋ ๊ธฐ๋ฅ
- HTTP ์์ฒญ BODY๋ฅผ ๊ฐ์ฒด๋ก ๋ณํ
@ResponseBody
- ๊ฐ์ฒด๋ฅผ JSON/XML ํ์์ผ๋ก ๋ณํํด์ ์ ์กํ ์ ์๋ ๊ธฐ๋ฅ
- ๊ฐ์ฒด๋ฅผ HTTP ์๋ต BODY๋ก ๋ณํ
@Valid, BindingResult