Spring Annotation
Bean Annotations
@Component
@Component
๋ชจ๋ Spring ๊ด๋ฆฌ ๊ตฌ์ฑ ์์๋ฅผ ํ์ํ๋ค.
@Service
@Service
์๋น์ค ๊ณ์ธต์ ํด๋์ค๋ฅผ ํ์ํ๋ ์๋ ธํ ์ด์ ์ ๋๋ค.
๋น์ฆ๋์ค ๋ก์ง์ ๋ณด์ ํ๊ณ ์์์ ๋ํ๋ด๊ธฐ ์ํด์ ์ ๋๋ค.
@Repository
@Repository
๋ฐ์ดํฐ๋ฒ ์ด์ค ์ ์ฅ์ ์ญํ ์ ํ๋ ์ง์์ฑ ๊ณ์ธต์ ํด๋์ค์ ์ถ๊ฐํฉ๋๋ค.
์ญํ ์ ์ง์์ฑ ๊ด๋ จ ์์ธ๋ฅผ ํฌ์ฐฉํ์ฌ Spring์ ํตํฉ๋ unchecked exceptions๋ก ๋ค์ ๋ฐ์์ํค๋ ๊ฒ์ ๋๋ค.
@Component Scanning
@Component Scanning
์ค์บํ annotation configuration ํด๋์ค์ ํจํค์ง๋ฅผ ๊ตฌ์ฑํ๋ค
basePackages ๋๋ ๊ฐ ์ธ์(value๋ basePackages์ ๋ณ์นญ) ์ค ํ๋๋ฅผ ์ฌ์ฉํ์ฌ ๊ธฐ๋ณธ ํจํค์ง ์ด๋ฆ์ ์ง์ ์ง์ ํ ์ ์์ต๋๋ค.
์ธ์๋ฅผ ์ง์ ํ์ง ์์ผ๋ฉด @ComponentScan annotation ํด๋์ค๊ฐ ์๋ ๋์ผํ ํจํค์ง์์ ์ค์บ์ด ๋ฐ์ํฉ๋๋ค.
@Controller
@Controller
Controller ๊ณ์ธต์ ํด๋์ค๋ฅผ ํ์ํ๋ ์๋ ธํ ์ด์ ์ ๋๋ค.
@Configuraion
@Configuraion
@Bean
์ด ๋ฌ๋ ค์๋ dean definition ๋ฉ์๋๋ฅผ ํฌํจํ ์ ์์ต๋๋ค.
Web Annotations
@RequestMapping
@RequestMapping
@Controller
ํด๋์ค ๋ด๋ถ์ request handler ๋ฉ์๋๋ฅผ ํ์ํฉ๋๋ค.path, or its aliases, name, and value: which URL the method is mapped to
method: compatible HTTP methods
params: filters requests based on presence, absence, or value of HTTP parameters
headers: filters requests based on presence, absence, or value of HTTP headers
consumes: which media types the method can consume in the HTTP request body
produces: which media types the method can produce in the HTTP response body
@RequestBody
@RequestBody
maps the body of the HTTP request to an object:
์ญ์ง๋ ฌํ๋ ์๋์ด๋ฉฐ ์์ฒญ์ ์ฝํ ์ธ ์ ํ์ ๋ฐ๋ผ ๋ค๋ฆ ๋๋ค.
@PathVariable
@PathVariable
์ด annotation์ ๋ฉ์๋ ์ธ์๊ฐ URI ํ ํ๋ฆฟ ๋ณ์์ ๋ฐ์ธ๋ฉ๋์ด ์์์ ๋ํ๋ ๋๋ค.
@RequsetParam
@RequsetParam
accessing HTTP request parameters
@ResponseBody
@ResponseBody
Spring์ ๋ฉ์๋์ ๊ฒฐ๊ณผ๋ฅผ ์๋ต์ผ๋ก ์ทจ๊ธํฉ๋๋ค.
@ExceptionHandler
@ExceptionHandler
์ง์ ๋ ์์ธ๋ฅผ ์ฒ๋ฆฌํ๋ ์ง์ ํ ์ค๋ฅ ์ฒ๋ฆฌ๊ธฐ ๋ฉ์๋๋ฅผ ์ ์ธํ ์ ์์ต๋๋ค.
@ResponseStatus
@ResponseStatus
์ํ๋ ์๋ต HTTP ์ํ๋ฅผ ์ง์ ํ ์ ์์ต๋๋ค.
@RestController
@RestController
combines @Controller and @ResponseBody.
@ModelAttribute
@ModelAttribute
์ด๋ฏธ ๋ชจ๋ธ์ ์๋ ์์์ ์ก์ธ์ค ํ๋ค.
Core Annotations
@Autowired
@Autowired
Spring์ด ์ฃผ์ ํ ์์กด์ฑ์ ํ์ํฉ๋๋ค.
@Bean
@Bean
@Bean
marks a factory method which instantiates a Spring bean
@Qualifier
@Qualifier
๋ชจํธํ ์ํฉ์์ ์ฌ์ฉํ๋ ค๋ bean id ๋๋ bean ์ด๋ฆ์ ์ ๊ณตํ๊ธฐ ์ํด @Autowired์ ํจ๊ป @Qualifier๋ฅผ ์ฌ์ฉํฉ๋๋ค.
@Required
@Required
XML์ ํตํด ์ฑ์ฐ๋ ค๋ ์์กด์ฑ์ ํ์ํ๊ธฐ ์ํ setter ๋ฉ์๋์
@Required
์ ์ฌ์ฉํ๋ค.
@Value
@Value
์์ฑ ๊ฐ์ Bean์ ์ฃผ์ ํ ์ ์๋ค.
@DependsOn
@DependsOn
annotation์์ ์ค์ ํ bean์ ๋จผ์ ์ด๊ธฐํ ํ annotation ๋ฌ๋ฆฐ bean์ ์ด๊ธฐํํ๋ค.
@Lazy
@Lazy
์์ฉ ํ๋ก๊ทธ๋จ ์์ ์๊ฐ ์๋๋ผ ์์ฒญ ์ bean์ ์์ฑํ ์ ์์ต๋๋ค.
@Lookup
@Lookup
@Lookup ์ด๋ ธํ ์ด์ ์ด ๋ถ์ ๋ฉ์๋๋ ํธ์ถํ ๋ ๋ฉ์๋์ ๋ฆฌํด ์ ํ ์ธ์คํด์ค๋ฅผ ๋ฆฌํดํ๋๋ก Spring์ ์ง์ํฉ๋๋ค.
@Primary
@Primary
๋์ผํ ์ ํ์ ์ฌ๋ฌ bean์ค ํน์ bean์ ์ฌ์ฉ์ ์ฌ์ฉํฉ๋๋ค.
@Scope
@Scope
@Scope๋ฅผ ์ฌ์ฉํ์ฌ @Component ํด๋์ค ๋๋ @Bean ์ ์์ ๋ฒ์๋ฅผ ์ ์ํฉ๋๋ค.
@Profile
@Profile
ํน์ ํ๋กํ์ด ํ์ฑํ๋ ๊ฒฝ์ฐ์๋ง Spring์ด @Component ํด๋์ค ๋๋ @Bean ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋๋ก ํ๋ ค๋ฉด @Profile๋ก ํ์ํ ์ ์์ต๋๋ค.
@Import
@Import
์ด annotation์ ์ฌ์ฉํ์ฌ ๊ตฌ์ฑ component scanning ์์ด ํน์
@Configuration
ํด๋์ค๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
@ImportResource
@ImportResource
XML configurations์ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค.
@PropertySource
@PropertySource
์ ํ๋ฆฌ์ผ์ด์ ์ค์ ์ ๋ํ ์์ฑ ํ์ผ์ ์ ์ํ ์ ์์ต๋๋ค.
@PropertySources
@PropertySources
@PropertySource configurations์ ์ง์ ํ ์ ์์ต๋๋ค.
Last updated
Was this helpful?