Quick Steps To Developing Spring Applications – Don’t Miss
We will see the steps to be follow for developing any spring application, these are core level read carefully.
- Spring environment starts by loading spring configuration xml file into Resource Interface object, we call this loading process as bootstrapping (technically) of spring framework.
- Resource is an interface and ClassPathResource is an implemented class given by spring, both are given in org.springframework.core.io. *
Resource res = new ClassPathResource(“Our Config xml file name”);
- Actually this configuration file contains all bean configurations about our application [ some thing like struts.xml in struts 2 ]
- Next step is to bring spring IOC container into our program, it will be created by reading configuration xml through Resource object. Spring IOC container is called BeanFactory and this container is responsible for creating the bean objects and for injecting it’s dependencies through out our applications.
- BeanFactory is the interface and XmlBeanFactory is an implementation class of it, BeanFactory given in org.springframework.beans.factory. * and XmlBeanFactory is given in org.springframework.beans.factory.xml.* pack
BeanFactory factory = new XmlBeanFactory(res);
// given above Resource object…
Now you can get required object from spring container by calling getBean() method, while calling this method we need to pass the bean id as a parameter like.. getBean(bean id), and this method always returns Object class object and we need to type caste this into our bean type.
Object ob = factory.getBean(“id1”);
FirstBean fb = (FirstBean)ob;
Now you can call what ever you want from the object fb.
You Might Also Like
::. About the Author .::