반응형

@SpriongBootApplication
 . Springboot 를 실행하기 위한 중요한 역할을 담당한다
 . Springboot의 기본적인 설정이 선언되어 있다.

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
		@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {
 ....
 }

위 처럼 여러가지 meta Annotation 을 포함한다.
 - meta annotation ; 다른 annotation 을 정의하는데 사용되는 annotation을 의미
 
@Target
 . java complier가 해당 annotation이 적용될 대상을 결정할 때 사용된다.
 . 위의 코드를 보면 @SpringBootApplicaction의 target을 type으로 지정하고 있다.
 . ElementType은 PACKAGE, TYPE 등등이 존재한다.
 
@Retention
 . 해당 Annotation이 실제로 적용되고 유지되는 범위, 즉 해당 annotation의 lifecycle을 의미한다.
 . RUNTIME, CLASS, SOURCE 3가지가 존재한다.
 . @Retention(RetentionPolicy.RUNTIME)
 - compile 이후에도 JVM에 의해서 계속 참조가 가능하다.
 . @Retention(RetentionPolicy.CLASS)
 - Complier가 class를 참조할 때까지 유효하다.
 . @Retention(RetentionPolicy.SOURCE)
 - Complire 전까지만 유효하며, complier 이후에는 사라지게 된다.
 
=> 좀더 자세히
 . JVM은 Java source(.java 파일)를 complier가 complie 후에 Java byte code(.class 파일)로 변환한다.
위의  SOURCE는 .java까지 annotation이 남아 있다는 것이고, CLASS는 .class 까지,
RUNTIME은 runtime 환경에서까지 남는다는 것이다.
RUNTIME 은 실행중에도 annotation의 정보를 확인할 수 있다.
SORUCE의 경우는 특정 byte code를 생성한 후 .class에서는 사라지기며, lombok의 Getter, Setter를 예로 들 수 있다.
CLASS의 경우 Maven / Gradle을 통해 다운 받은 lib등의 jar 파일에는 source가 포함되어 있지 않기 때문에 필요하다.
 
@Documented
 . javadoc으로 api 문서를 만들 때 annotation에 대한 설명도 포함하도록 지정하는 역할을 한다.
 
@Springbootconfiguration

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Configuration
@Indexed
public @interface SpringBootConfiguration {
 .....
}

 . @Springbootconfiguration의 세부 사항을 보면 위의 코드와 같이 meta annotation으로 구성되어 있다.
이 중 @Configuration 이 중요한데 @Configuration 이 존재할 때 spring은 java configurure 설정 class로 간주하며 Bean으 로 등록하게 된다.

@Inherited
. 해당 annotation이 붙은 경우 자식 class까지 annotation을 상속하게 된다.

 

반응형

'SpringBoot' 카테고리의 다른 글

Spring에서의 IOC  (0) 2023.12.11
IOC란 무엇인가?  (0) 2023.12.11
Bean과 Component  (0) 2023.11.30
SpringBoot와 SpringMVC의 차이와 특성에 대하여  (0) 2023.11.29
Springboot에서의 cookie, session 사용방법  (0) 2023.11.14
Posted by Sweetmeats_boy

블로그 이미지
Sweetmeats_boy

태그목록

Yesterday
Today
Total

달력

 « |  » 2024.9
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

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함