FileSystemXmlApplicationContext과 ClassPathXmlApplicationContext
FileSystemXmlApplicationContext
보통 ApplicationContext 생성자는 XML 파일과 같은 설정파일의 리소스의 위치 경로를 문자열이나 문자열의 배열로 받는다.
이때, ClassPathXmlApplicationContext("conf/servlet-context.xml"); 과 같이 사용한다면 어플리케이션 컨텍스트에 의존되어 사용될 클래스패스 경로에서 로드가 될 것이다.
하지만, FileSystemXmlApplicationContext로 ApplicationContext를 생성한다면
소스를 작성한 현재 소스가 실행되어지는 워킹디렉토리에서 상대적인 파일시스템의 위치 경로에 있는 파일이 로드되게 된다.
<<ApplicationContext 구현체 Class>>
(1) ClassPathXmlApplicationContext : ClassPath에 위치한 xml 파일을 읽는다.
ApplicationContext context = new ClassPathXmlApplicationContext("spring-beans.xml");
ApplicationContext context = new FileSystemXmlApplicationContext("/src/main/webapp/WEB-INF/spring/spring-beans.xml");
FileSystemXmlApplicationContext가 동작되기 위해서는 해당 소스를 가진 클래스가
src 폴더에 있어야 가능하다.
그렇기 때문에 xml 파일이 ClassPath 경로에 위치해 있다면 ClassPathXmlApplicationContext를 통해 ClassPath 레벨에 접근하는 것이 바람직하다.
ps)
(1) classpath*: 접두사
classpath*: 접두사는 뒤에 붙은 파라미터명과 일치하는 모든 클래스패스 리소스들을 읽으라는 것으로 해석된다.
(2) ApplicationContext
스프링이 관리하는 빈들이 담겨있는 컨테이너. 스프링 안에는 여러 종류의 애플리케이션 컨텍스트 구현체가 있는데, ApplicationContext라는 인터페이스를 구현한 객체들이 다 이 애플리케이션 컨텍스트이다.