This Session Talks about the Flavors of Application Context,
- ClassPathXmlApplicationContext : Loads Context Definition From XML File Located in Classpath
- ApplicationContext context=new
ClassPathXmlApplicationContext("bean.xml");
- FileSystemXmlApplicationContext : Loads from an xml loacted in filesystem (absolute/relative path should must be mentioned)
- ApplicationContext context=new
FileSystemXmlApplicationContext("c:/bean.xml");
- XmlWebApplicationContext : Loads From xml file existing with in web application context.
- ApplicationContext context=new
XmlWebApplicationContex("bean.xml"); - Consider Following xml Bean definition,
- <bean name="hello" class="org.srinidhi.beans.Helloworld">
- getBean() method of context will actually get the instantiated object of Helloworld,
public static void main(String args[]){
ApplicationContext context = new FileSystemXmlApplicationContext("c:/bean.xml");
Helloworld hw = (Helloworld ) context .getBean("hello");
hw.sayHello(); // Calling method of Helloworld Class.
}
Hope You like this session.