In this tutorial you will learn about the inner bean in spring framework.
In this tutorial you will learn about the inner bean in spring framework.In the Spring framework an inner bean definition does not required to defined id or name of bean. The reason behind this is that the container ignores these values. Inner bean is used when a bean is used for one particular property. When </bean> element is defined inside the <property/> or <constructor-arg/> it is known as inner bean.
InnerBean.java
package innerbean.example;
|
OuterBean.java
package innerbean.example;
|
InnerBeanMain.java
package innerbean.example; import org.springframework.beans.factory.BeanFactory; import org.springframework.context.support. ClassPathXmlApplicationContext; public class InnerBeanMain { public static void main(String[] args) { BeanFactory beanfactory = new ClassPathXmlApplicationContext("context.xml"); OuterBean bean = (OuterBean) beanfactory.getBean("outer"); System.out.println(bean); } } |
<!-- Inner Bean Example --> |
OuterBean [InnerBean=Inner [address=patna, name=satya]] |