AnnotationConfigApplicationContext
ApplicationContext 구현
@Configuration 클래스가 입력으로 제공
@Component, JSR-330
스프링 컨테이너 인스턴스화 특징
@Configuration
public class AppConfig {
@Bean
public UserService userService() {
return new UserServiceImpl(userRepository());
}
@Bean // Bean 의존성 정의 가능
public OrderService orderService() {
return new OrderServiceImpl(userRepository(), discountInfo());
}
...
}
@Bean
public interface BaseConfig {
@Bean
default TransferServiceImpl transferService() {
return new TransferServiceImpl();
}
}
@Configuration
public class AppConfig implements BaseConfig {
...
}
@Configuration
@Import
@Configuration()
public class ConfigA {
private final B b;
(@Autowired)
public ConfigA(B b){ this.b = b }
@Bean
public A a() {return new A();}
@Bean
public IncludeB includeB() {
return new IncludeBImpl(b);
}
}
@Configuration // @Component를 포함하고 있음
@Import(ConfigA.class)
public class ConfigB {
@Bean
public B b() {return new B();}
}
// 컨텍스트 인스턴스화 할 때, B만 제공해도 됨
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigB.class);
@ComponentScan
@ComponentScan vs @Configuration
@Configuration
@ComponentScan
public class AutoAppConfig {
}
@ComponentScan(excludeFilters = @Filter(type = FilterType.ANNOTATION, classes = Configuration.class))
basePackages
컴포넌트 스캔 대상 (@Component를 포함한 어노테이션)
@ComponentScan filter : 참고자료