ApplicationContext와 빈 설정
xml 설정 파일
public class DemoApplication {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("application.xml");
String[] beanDefinitionNames = context.getBeanDefinitionNames();
// [bookService, bookRepository]
System.out.println(Arrays.toString(beanDefinitionNames));
// 출력된 빈 이름으로 불러온다.
BookService bookService = (BookService) context.getBean("bookService");
// true
System.out.println(bookService.bookRepository != null);
}
}public class BookService {
BookRepository bookRepository;
public void setBookRepository(BookRepositry bookRepository) {
this.bookRepository = bookRepository;
}
}컴포넌트 스캔
자바 설정 파일
@ComponentScan 애너테이션
Last updated