π λ€μ΄κ°λ©°
SpringBootλ₯Ό μ΄μ©ν΄ κ°λ°μ νλ€λ³΄λ©΄ μ λ§ λ§μ΄ μ¬μ©νκ² λλ κ² μ€ νλκ° μ΄λ Έν μ΄μ μ λλ€. μ’ λ₯λ λ§€μ° λ€μνλ©°(@RestController, @Component.. λ±) Personal μ΄λ Έν μ΄μ μ λ§λ€ μλ μμ΅λλ€. μ€λμ μ΄λ¬ν Springμμ μ΄λ Έν μ΄μ μ μ μμ λμμ리μ λν΄μ μμ보λλ‘ νκ² μ΅λλ€.
π Annotation μ μ μ
μ΄λ Έν μ΄μ μ λν μ μλ₯Ό μλ° κ³΅μ λ¬Έμμμ μ°Ύμ보면
https://docs.oracle.com/javase/tutorial/java/annotations/
Lesson: Annotations (The Java™ Tutorials > Learning the Java Language)
The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available. See Java Language Changes for a summary of updated
docs.oracle.com
Annotations, a form of metadata, provide data about a program that is not
part of the program itserlf. Annotaions have no direct effect on the operation of the code they annotate.
μ¬μ μ μΈ μλ―Έλ‘λ μ£Όμμ λ»νλ©° μ¦, μ½λ μ¬μ΄μ μ£Όμμ²λΌ μ°μ΄λ©΄μ νΉλ³ν μλ―Έ, κΈ°λ₯μ μννλλ‘ νλ κΈ°μ λ‘
μ½λμ λμμλ μ§μ μ μΌλ‘ μν₯μ μ£Όμ§ μκ³
νλ‘κ·Έλ¨μκ² μΆκ°μ μΈ μ 보λ₯Ό μ 곡ν΄μ£Όλ λ©ν λ°μ΄ν°μ λλ€.
μΌλ°μ μΌλ‘ μλμ κ°μ μΈ κ°μ§ μ©λλ‘ νμ©λ©λλ€.
- μ»΄νμΌλ¬μκ² μ½λ μμ± λ¬Έλ² μλ¬λ₯Ό 체ν¬νλλ‘ μ 보λ₯Ό μ 곡
- μννΈμ¨μ΄ κ°λ°ν΄μ΄ λΉλλ λ°°μΉ μ μ½λλ₯Ό μλμΌλ‘ μμ±ν μ μλλ‘ μ 보λ₯Ό μ 곡
- λ°νμ μ νΉμ κΈ°λ₯μ μ€ννλλ‘ μ 보λ₯Ό μ 곡
π Annotation νμΌ μ μνκΈ°
@Target({ElementType.[μ μ©λμ]})
@Retention(RetentionPolicy.[μ 보μ μ§λλ λμ])
public @interface [μ΄λ
Έν
μ΄μ
μ΄λ¦]{
...
}
μ΄λ Έν μ΄μ νμΌμ μμ κ°μ΄ μ μνλ©° κ° μν©μ λ§κ² νμμ λ°λΌ μ μ©ν μ μμ΅λλ€.
Target μ€μ
ElementType Enum κ° | |
ANNOTATION_TYPE | μ΄λ Έν μ΄μ μ μΈ |
CONSTRUCTOR | μμ±μ μ μΈ |
FIELD | νλ μ μΈ (μ΄κ±° ν μμ ν¬ν¨) |
LOCAL_VARIABLE | μ§μ λ³μ μ μΈ |
METHOD | λ©μλ μ μΈ |
PACKAGE | ν¨ν€μ§ μ μΈ |
PARAMETER | Public Parameter |
TYPE | ν΄λμ€, μΈν°νμ΄μ€(μ£Όμ μ ν ν¬ν¨) λλ μ΄κ±° ν μ μΈ |
TYPE_PARAMETER | Type νλΌλ―Έν° μ μΈ (java 8μ μΆκ°) |
TYPE_USE | Type μ΄ μμλλ κ³³ (java 8dp μΆκ°) |
Retention μ€μ
RetentionPolicy Enum κ° | |
CLASS | μ»΄νμΌλ¬μ μν΄ ν΄λμ€ νμΌμ κΈ°λ‘λμ§λ§ λ°νμμλ μ μ§λμ§ μμ΅λλ€. |
RUNTIME | μ»΄νμΌλ¬μ μν΄ ν΄λμ€ νμΌμ κΈ°λ‘λκ³ λ°νμμ μ μ§λ©λλ€. |
SOURCE | μμ€μλ§ λ°μλμ΄ μ»΄νμΌλ¬μ μν΄ μμ λ©λλ€. |
π Annotationμ λμμ리
Annotation μ λμμ리λ μλ κ·Έλ¦Όκ³Ό κ°μ΅λλ€.
Annotation Processorκ° ν΄λΉ Annotation κ³Ό Annotationμ΄ λΆμ λΆλΆμ μμ§ν΄μ byte codeλ₯Ό λ§λ€κ³ .class νμΌμ λ§λλλ€.
μ΄ κ³Όμ μμ Parserλ μμ§(μ€ν)λμ§ μμ Annotation Processor κ° μλμ§ νμΈν ν
λͺ¨λ μνν λκΉμ§ μμ μ λ°λ³΅ν©λλ€.
Oracle μ Processing μ λ°λ³΅ νμλ₯Ό Round λΌκ³ λΆλ¦ λλ€. ν Roundμμλ νλμ Annotationμ ν΅ν΄
Boilerplate codeλ₯Ό λ§λ€κ³ λμ λ€μ Parserκ° κ²μ¬λ₯Ό νλλ° μ΄λ Annotationμ΄ μ€μ²©λμ΄ μλ κ²½μ°
μμ§ λμνμ§ μμ(Boilerplate codeλ₯Ό λ§λ€μ§ μμ) Annotationμ΄ μμ μ μκΈ° λλ¬Έμ λλ€.
.class νμΌμ κΈ°λ°μΌλ‘ jvm μ ν΄λμ€ λ‘λμ μ¬λΌκ°λλ° κ·Έμ μ annotation μ΄ λΆμ μ½λλ€μ΄ μ λ°λμ΄μΌ ν©λλ€.
μ°Έκ³ :
https://hirlawldo.tistory.com/43
https://velog.io/@gale4739/Spring-Boot-%EC%96%B4%EB%85%B8%ED%85%8C%EC%9D%B4%EC%85%98
'BackEnd > SpringBoot' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
CircuitBreaker λ‘ μλ°©νλ μ₯μ μ ν(1) (0) | 2023.12.10 |
---|---|
Spring Transaction μ λν μ΄ν΄ (0) | 2023.09.20 |
μ€νλ§ λΆνΈ λ‘컬 μΊμ μ μ©νκΈ° (0) | 2023.06.25 |
Feign Client λ₯Ό νμ©νμ¬ μΈλΆν΅μ μ°λνκΈ° (0) | 2023.04.22 |
String ννκ° μλ LocalDateTimeκ·Έλλ‘ λ°μ보μ! (1) | 2023.01.01 |