ApplicationContext
The ApplicationContext is the central interface within a Spring application for providing configuration information to the application. It is read-only at run time, but can be reloaded if necessary and supported by the application. A number of classes implement the ApplicationContext interface, allowing for a variety of configuration options and types of applications.
1) One Way
package
com.springpg;
import
org.springframework.context.support.GenericXmlApplicationContext;
public
class
Test {
public
static
void
main(String[] args)
{
//
TODO
Auto-generated method stub
GenericXmlApplicationContext
cn
= new
GenericXmlApplicationContext("NewFile.xml");
Classpg
obj
= cn.getBean("helloWorld",Classpg.class);
obj.show();
}
}
2) Second Way
package
com.springpg;
import
org.springframework.context.ApplicationContext;
import
org.springframework.context.support.ClassPathXmlApplicationContext;
public
class
Test {
public
static
void
main(String[] args)
{
//
TODO
Auto-generated method stub
ApplicationContext
context
= new
ClassPathXmlApplicationContext("NewFile.xml");
Classpg obj
= (Classpg) context.getBean("helloWorld");
obj.show();
}
}