Wednesday, May 30, 2012

Spring Framework- Introduction to ApplicationContext container


To take the full advantage of the spring framework, compare to bean factory, Applicationcontext is more better .Application Context is more advanced container to load Application Context.
On the surface, an AplicationContext is much the same as a BeanFactory both load bean definition, and dispense beans upon request. But the ApplicationContext offer much more-
·         ApplicationContext provide   generic way to load file resources, such as images.
·         ApplicationContext can publish events to bean that are registered as listeners.

The BeanFactory are preferred where the resources are short,such as a mobile device.  There are many    implementation of application context but commonly used:
1.       ClasspathXmlApplicationContext- Loads context definition from an xml file located in class path, treating context definition files as class-path resources.
2.       FileSystemXmlApplicationContext-Loads context definitions from an XML file in the file system.
3.       XmlWebApplicationContext-Loads context definitions from an Xml file contained within a web application.

Loading an application context from the file system or from the classpath  is similar to load bean into a BeanFactory.
Example of how to load  FileSystemApplicationContext:
ApplicationContext context=new FileSystemAplicationContextC(“c:/filename.xml”);


Similarly , can load an application context from within the application class path using ClassPathXmlApplicationContext:
ApplicationContext context=new ClassPathXmlApplicationContext("filename.xml");


For Further Reading,
General, Java, spring

0 comments:

Post a Comment


 

Site Status

Man Behind Technical Today

Hello, I am Navin Bansal. I am a student of MCA in Rajsthan Institute of Engineering and Technology and owner of this blog. I share my view and ideas among people.