본문 바로가기
Spring

@Configuration

by 지금 느낌 그대로 2021. 1. 10.

1. 특징

  • 스프링 3.X 이상의 프레임워크에서는 XML 파일에서 하는 Bean의 정의를 자바클래스로서 선언할수 있게 한다.
  • Spring IoC 컨테이너에게 설정 정보(Meta Data)임을 알려줌
  • XML 파일에서 아래와 같이 설정하는 것과 동일한 역할을 수행( 클래스를 스프링 Bean으로 등록하고 이미 등록된 bean들에 대해 어노테이션을 활성화하는 것)
<beans>
	<context:annotation-config />
	<bean class="com.sample.AppConfig" />
</beans>    

 

  • 개발자가 직접 제어할 수 없는 외부 라이브러리 혹은 설정을 위한 클래스를 Bean으로 등록할 때 @Bean 어노테이션과 함께 사용되기도 함. (단독으로도 사용 가능)
  • @Bean 단독 사용 시, bean 등록이 되긴 하지만 IoC 컨테이너에서 싱글톤 객체로 생성되지 않음
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Configuration {

	@AliasFor(annotation = Component.class)
	String value() default "";


	boolean proxyBeanMethods() default true;

}

@Configuration 를 선언한 코드를 보면  Target이 Type이므로 클래스,인터페이스,Enum 에서만 사용가능하다.

References

https://mangkyu.tistory.com/75

 

[SpringBoot] @Bean, @Configuration, @Component 어노테이션

기존의 Spring MVC에서는 xml을 활용하여 Bean을 등록하고 있었다. 하지만 프로젝트의 규모가 커짐에 따라 사용하는 요소들을 xml에 등록하는 것이 상당히 번거로워 져서 어노테이션(Annotation, @)를 활

mangkyu.tistory.com

http://tech.javacafe.io/spring/2018/11/04/%EC%8A%A4%ED%94%84%EB%A7%81-Configuration-%EC%96%B4%EB%85%B8%ED%85%8C%EC%9D%B4%EC%85%98-%EC%98%88%EC%A0%9C/

 

스프링 @Configuration 어노테이션 예제

https://examples.javacodegeeks.com/enterprise-java/spring/spring-configuration-annotation-example/ 의 글을 번역해서 올림니다. 스프링 3.x 프레임워크는 XML 파일에서의 bean정의를 자바클래스로 선언할 수 있다. 이 예제

tech.javacafe.io

https://gmlwjd9405.github.io/2018/11/10/spring-beans.html

 

[Spring] Spring Bean의 개념과 Bean Scope 종류 - Heee's Development Blog

Step by step goes a long way.

gmlwjd9405.github.io