@DataJpaTest @ActiveProfiles(value = "test") @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) @Import({DataBaseConfig.class, QuerydslConfig.class, SpringJpaProperties.class}) @ContextConfiguration(classes = { EnableConfigurationProperties.class, ConfigurationPropertiesScan.class }) @ComponentScan("my.project.domain.repository") 위 소스에 있는 annotation들을 붙이면 전체 spring cont..
앞서 봤던 것 처럼 Bean은 BeanDefinition 형태로 map에 저장된다. 그렇다면 Bean이 언제 객체화 되고 초기화가 이루어질까? public class AnnotationConfigApplicationContext extends GenericApplicationContext implements AnnotationConfigRegistry { private final AnnotatedBeanDefinitionReader reader; private final ClassPathBeanDefinitionScanner scanner; public AnnotationConfigApplicationContext() { this.reader = new AnnotatedBeanDefinitionReade..

ApplicationContext 부터 천천히 따라가며 Bean이 어떤 과정을 통해 등록 되는 지 알아보자. ApplicationContext BeanFactory를 상속 받은 HierarchicalBeanFatory, ListaableBeanFactory를 상속 받고 있고, 또한 다른 여러 인터페이스도 상속받고 있다. ApplicationContext는 Bean을 등록하고 가져오는데 쓰이는 것으로만 생각하고 있었으나, 소스를 열어보니 그렇지 않았다. 실제로 ApplicationContext의 설명을 보면 Application의 Component에 접근할 수 있는 BeanFactory 메서드 제공 - ListableBeanFactory 인터페이스 포괄적인 방식(Generic Fashion)으로 file ..
Bean @Bean 빈 객체를 참조할 때 사용 객체를 생성하고 알맞게 생성해야 한다. 개발자가 컨트롤 하기 불가능한 외부 라이브러리 들을 Bean 으로 등록하고 싶은 경우에 사용 예를 들어 ObjectMapper 의 경우 ObjectMapper 클래스에 @Component를 선언할 순 없으니 ObjectMapper의 인스턴스를 생성하는 매서드를 만들고, 해당 메소드에 @Bean을 선언하여 Bean으로 등록한다. bean? 스프링 IOC 컨테이너가 관리하는 객체. Controller, RestController @Controller 스프링 MVC 에서 컨트롤러로 사용한다. @RestController @Controller, @ResponseBody 을 합쳐놓은 어노테이션. @RestController pu..
- Total
- Today
- Yesterday