Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

SOURCE_CODE_SPRING_EL_DEMO_Govind package com; import org.springframework.context.ApplicationContext; import org.springframework.context.support.

ClassPathXmlApplicationContext; public class Client { public static void main(String[] args) {

ApplicationContext context = new ClassPathXmlApplicationContext("app.xml"); testA obj = (testA) context.getBean("a"); System.out.println(obj.getName2()); System.out.println(obj.getBb()); }

package com; public class testA { private testB bb; public testB getBb() { return bb; } public void setBb(testB bb) { this.bb = bb; } public String getName2() { return name2; } public void setName2(String name2) { this.name2 = name2; } private String name2; }

package com; public class testB {

private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getQty() { return qty; } public void setQty(int qty) { this.qty = qty; } private int qty; }

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="b" class="com.testB"> <property name="name" value="Abcddd" /> <property name="qty" value="10" /> </bean> <bean id="a" class="com.testA"> <property name="bb" value="#{b}" /> <property name="name2" value="#{b.name}" /> </bean> </beans>

You might also like