Inheritance Demo, In the example given below we are going to tell about the inheritance in the Spring framework. By inheritance we mean a way of forming new classes using classes that have already been defined. Here we have created a simple bean and used this bean as a template for creating other beans.
parent="parent":-Specify that this bean is inheriting the properties of some other bean.
context.xml
"1.0" encoding="UTF-8"?>
|
Main.java
This is the file through which we are retrieving the property of the bean defined above. Some of the methods which are used here are as follows:-
XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("context.xml")):-This method creates an instance of the XmlBeanFactory which is used to read bean definition from an XML document
new ClassPathResource("context.xml"):-Creates a new ClassPathResource for ClassLoader .Here the context.xml is the file which is to be loaded.
(bf.getBean("child")):-This method returns an instance of the bean named "child", which is shared or independent, of the given bean name.
(bf.getBean("subchild")):-This method returns an instance of the bean named "subchild", which is shared or independent, of the given bean name.
stringBuilder.append("Bean"):-This is the method of the class string Builder which appends the specified string to this character sequence.
|
Output of the program
Nov 25, 2008 3:39:29 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [context.xml] ===============Inheritance demo================= Bean{name='Roseindia.net', address=Rohini} Bean{name='Roseindia.net', address=null} BUILD SUCCESSFUL (total time: 1 second) |
0 comments:
Post a Comment