본문 바로가기

SpringFramework Core - I. IoC 컨테이너

(101)
10.7. 자동 탐지된 컴포넌트들에 Scope 제공하기 원문: https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html#beans-scanning-scope-resolver 스프링의 관리를 받는 일반적인 컴포넌트들처럼, 자동 탐지된 컴포넌트는 기본값이면서도 가장 흔하게 'singleton' scope를 갖는다. 그러나 가끔은 @Scope 어노테이션을 통해 다른 scope를 설정해야될 때가 있다. 그럴 때는 다음 예시처럼 어노테이션 안에 scope의 이름을 제공하면 된다. @Scope("prototype") @Repository public class MovieFinderImpl implements MovieFinder { // ... } ※ @Scope 어..
10.6. 자동 탐지된 컴포넌트들에 이름 붙이기 원문: https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html#beans-scanning-name-generator 스캐닝 과정에서 컴포넌트가 자동으로 탐지될 때, 스캐너의 BeanNameGenerator 전략에 따라 bean의 이름이 생성된다. 기본적으로, 어떤 스프링 stereotype 어노테이션이든(@Component, @Repository, @Service) 이름 'value'를 가지고 있으며 그 덕분에 bean 정의에 이름을 부여할 수 있다. 만약 그런 어노테이션들이 이름 'value'를 가지고 있지 않거나 탐지된 컴포넌트가 없다면, 기본 bean 이름 생성기가 소문자로 변환된 non-qua..
10.5. 컴포넌트 안에서 bean 메타데이터 정의하기 원문: https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html#beans-factorybeans-annotations 스프링 컴포넌트들은 컨테이너에게 bean 정의 메타데이터 또한 제공한다. 여러분은 @Configuration이 붙은 클래스에서 bean의 메타데이터를 정의하는 @Bean 어노테이션을 통해 이 일을 할 수 있다. 다음 예시는 그 방법을 보여준다. @Component public class FactoryMethodComponent { @Bean @Qualifier("public") public TestBean publicInstance() { return new TestBean("publ..
10.4. 스캐닝을 커스터마이즈하기 위해 필터 사용하기 원문: https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html#beans-scanning-filters 기본적으로, @Component, @Repository, @Service, @Controller, @Configuration, @Component를 포함한 커스텀 어노테이션 등이 붙은 클래스들만이 후보 컴포넌트로서 탐지된다. 그러나 커스텀한 필터를 적용함으로써 이 행동을 바꾸거나 확장시킬 수 있다. 커스텀한 필터들을 @ComponentScan 어노테이션의 includeFilters나 excludeFilters 속성에 추가하자(또는 XML 설정의 의 자식인 이나 ). 각 필터 요소들은 type과 ex..
10.3. 자동적으로 클래스를 찾아 bean 정의로 등록시키기 원문: https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html#beans-scanning-autodetection 스프링은 stereotype인 클래스들을 자동으로 찾아 ApplicationContext에 적절한 BeanDefinition 인스턴스로 등록시킨다. 예를 들어, 다음 두 클래스들은 그러한 자동 탐색의 대상이 된다. @Service public class SimpleMovieLister { private MovieFinder movieFinder; public SimpleMovieLister(MovieFinder movieFinder) { this.movieFinder = movieFind..
10.2. 메타 어노테이션과 구성 어노테이션 사용하기 원문: https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html#beans-meta-annotations 스프링으로부터 제공되는 많은 어노테이션들이 메타 어노테이션으로써 사용될 수 있다. 메타 어노테이션은 다른 어노테이션에 적용될 수 있는 어노테이션이다. 예를 들어, @Service 어노테이션은 @Component에 대한 메타 어노테이션이다. 다음 예시를 보자. @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Component public @interface Service { // ... } 메타 어노테이션들을 결합해..
10.1. @Component와 더 많은 Stereotype 어노테이션들 원문: https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html#beans-stereotype-annotations @Repository 어노테이션은 DAO로 알려진 저장소의 역할 또는 stereotype을 수행하는 클래스를 위한 표시이다. 이 표시를 사용할 때에는 예외들의 번역이 자동적으로 이루어진다. 이는 '예외 번역'에 설명되어 있다. 스프링은 더 많은 stereotype 어노테이션들을 제공한다. @Component, @Service, @Controller와 같은 것들이다. @Component는 스프링의 관리를 받는 컴포넌트를 포괄하는 stereotype이다. @Repository, @Servic..
10. 클래스패스 스캐닝과 관리받는 컴포넌트들 원문: https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html#beans-classpath-scanning 이 장에서 대부분의 예시들은 설정 메타데이터를 설정하는 것에 XML을 사용하였다. 이전 장에서는(어노테이션 기반의 컨테이너 설정) source-level 어노테이션들을 통해 어떻게 많은 설정 메타데이터들을 제공할 수 있는지 설명했다. 하지만 그 예시들에서도 "기본"이되는 bean 정의들은 XML 파일에 명확히 설정되어있었다. 어노테이션들은 단지 의존성 주입을 해냈던 것이다. 이 장에서는 클래스패스를 스캐닝함으로써 후보가 되는 컴포넌트들을 찾아내는 방법들에 대해 설명한다. 후보 컴포넌트들은 필터 ..