본문 바로가기

java

@Component와 @Configration & Stereo type

@Component와 @Bean의 차이점을 궁금해 찾아봤다. 

 

 

- @Bean은 @Configration과 함께 쓰인다는 점

 

- @Configration의 Annotation을 열어보면 @Component가 선언되어 있다

   그렇기 때문에 @Bean 으로 선언되지 않은 Method 도 @Autowired의 대상이 되지만 이렇게 구현 하면 의미가 없다. 

 

- @Component는 @Bean을 비교 할 것이 아니라 @Configration과 비교 해야 할 것

 

- @Bean은 stereo type 이다. 

   stereo type은 컴파일러 뿐 아니라 개발자에게도 annotation의 역할을 한다. spring에서는 stereo type 들이 꽤나 많다. 

   Annotation을 보면 ElementType.Method이다.

* stereo type 이 왜 중헌지 알게된 개발자 블로그

 

- 왜 이름을 @Configration이라고 지었을까. Configration과 관련된 역할을 하라고 명명한 것이 아닌가 싶다.

 

- @Component와 @Configration은 각각 역할에 맞게 사용해야 한다. Component의 Target은 ElementType.TYPE이다

 

* Component에서 @Indexed라는 annotation이 보인다. 공부는 하면 할 수록 계속 꼬리를 물고 나아갈 길이 나타난다. 

 

'java' 카테고리의 다른 글

interface와 abstract  (0) 2019.10.22
Spring AOP  (0) 2019.10.14
springboot + gradle + yaml  (0) 2019.10.02
SpringBoot 단상  (0) 2019.10.02
XML vs JSON vs YAML  (0) 2019.10.02