0% found this document useful (0 votes)
31 views

Source Code BasicEL Demo

The document demonstrates how to use Spring framework to configure and inject dependencies between classes. It defines three classes - testA, testB and a client class. testA has a property of type testB. testB has name and qty properties. The XML configuration defines beans for testB and testA, injecting the testB bean into testA using property injection. The client class retrieves the testA bean from the application context and prints its name2 property and referenced testB bean.

Uploaded by

govindbirajdar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Source Code BasicEL Demo

The document demonstrates how to use Spring framework to configure and inject dependencies between classes. It defines three classes - testA, testB and a client class. testA has a property of type testB. testB has name and qty properties. The XML configuration defines beans for testB and testA, injecting the testB bean into testA using property injection. The client class retrieves the testA bean from the application context and prints its name2 property and referenced testB bean.

Uploaded by

govindbirajdar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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