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]] |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.