꿀똥벌레
꿀똥벌레 개발 블로그
꿀똥벌레
전체 방문자
오늘
어제
  • 분류 전체보기 (90)
    • JAVA (17)
    • SPRING (14)
    • Elasticsearch (4)
    • GRADLE (2)
    • HTML, CSS (0)
    • JAVASCRIPT (0)
    • GIT (1)
    • Vue.js (1)
    • server (1)
    • Python (0)
    • IT리뷰 (0)
    • 인프라 (6)
    • IOS (21)
    • 디자인패턴 (20)
    • Kafka (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • springintegration
  • 스프링 인테그레이션
  • 스프링 인티그레이션
  • 인덱스 템플릿
  • spring integration
  • maxConnTotal
  • persistence connection
  • maxConnPerRoute
  • elasticsearch
  • SWIFT
  • ES
  • spring
  • persistent connection
  • java
  • KEEPALIVE
  • connectionRequestTimeout
  • Index
  • 엘라스틱서치
  • mappings
  • Index Template

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
꿀똥벌레

꿀똥벌레 개발 블로그

JAVA

java annotation

2021. 5. 17. 08:36

어노테이션은 기본적으로 메타 어노테이션으로 구성되어 있다.

메타 어노테이션

  1. @Retention
  • 자바 컴파일러가 어노테이션을 다루는 방법을 기술하며, 특정 시점까지 영향을 미치는지를 결정

종류

  • RetentionPolicy.SOURCE - 컴파일 전까지만 유효하고 컴파일 하면 사라진다.
  • RetentionPolicy.CLASS - 컴파일러가 클래스를 참조할때 까지만 유효하다. (class파일 에서도 존재는 하지만, invisible옵션을 통해 런타임 메모리에서는 제거됨)
  • RetentionPolicy.RUNTIME - 런타임에도 어노테이션이 유효하므로 reflection사용 가능
  1. @Target
  • 어노테이션이 적용될 수 있는 위치를 선택하는 메타 어노테이션

종류

  • ElementType.PACKAGE
  • ElementType.TYPE
  • ElementType.ANNOTATION_TYPE
  • ElementType.CONSTRUCTOR
  • ElementType.FIELD
  • ElementType.LOCAL_VARIABLE
  • ElementType.METHOD
  • ElementType.PARAMETER
  • ElementType.TYPE_PARAMETER
  • ElementType.TYPE_USE
  1. @Documented
  • 어노테이션을 javadoc에 포함시킨다
  1. @Inherited
  • 어노테이션을 상속 가능하도록 한다.
  1. @Repeatable
  • 어노테이션을 적용시 반복 사용할 수 있게 한다.

후에 어노테이션을 활용할땐 아래와 같이 활용한다.

Class targetClass = 생성할클래스.class;
obj = targetClass.newInstance();
Field[] fields = targetClass.getDeclaredFields();
for (Field field : fields) {
  InsertIntData annotation = field.getAnnotation(InsertIntData.class);

  if (annotation == null) continue;

  field.setAccessible(true);
  field.set(obj, annotation.data());
}

'JAVA' 카테고리의 다른 글

java CompletableFuture  (0) 2023.07.07
JPA @ElementCollection  (0) 2021.05.27
Jackson 어노테이션 정리  (0) 2021.04.30
JPA 캐시  (0) 2021.04.28
JPA 락 처리  (0) 2021.04.28
    꿀똥벌레
    꿀똥벌레
    개발자 꿀똥벌레 입니다.

    티스토리툴바