ClassPathXmlApplicationContext는 XML을 인식하고 beans로 관리하여 load 할 수 있다.
ex)
// Student Domain
public class Student{
private int no;
private String name;
// standard constructors, getters and setters
}
classPath경로에 applicationcontext.xml이 위치되어 있으며 아래 코드가 삽입되어 있다.
<beans ...>
<bean id="student" class="com.test.applicationcontext.Student">
<propert name="no" value="3" />
<property name="name" value="hong" />
</bean>
</beans>
ClassPathXmlApplicationContext를 사용
@Test
public void testUse(){
ApplicationContext context = new ClassPathXmlApplicationContext("applicationcontext.xml");
Student student = (Student) context.getBean("student");
assertThat(student.getNo(), equalTo(3));
assertThat(student.getName(), equalTo("hong"));
}
ApplicationContext context = new ClassPathXmlApplicationContext("ctx.xml", "ctx2.xml");