`
Advertisement
package decodejava;
import java.util.List;
public class Company
{
public String name;
public List<Employee> employees;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public List<Employee> getEmployees()
{
return employees;
}
public void setEmployees(List<Employee> employees)
{
this.employees = employees;
}
}
package decodejava;
public class Employee
{
public String name;
public int telNo;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getTelNo()
{
return telNo;
}
public void setTelNo(int telNo)
{
this.telNo = telNo;
}
}
Advertisement
package decodejava;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class Utility {
public static void main(String[] args)
{
ApplicationContext context = new FileSystemXmlApplicationContext("classpath:config.beans.xml");
Company company = context.getBean(Company.class);
List<Employee> listOfEmp = company.getEmployees();
for(Employee emp : listOfEmp)
{
System.out.println("Name of employee : " + emp.getName());
System.out.println("Employee telephone num : "+ emp.getTelNo());
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/context/spring-context.xsd
">
<bean id="CompanyBean" class="decodejava.Company">
<property name="employees">
<list>
<bean class="decodejava.Employee">
<property name="name" value="Emp1"></property>
<property name="telNo" value="111111"></property>
</bean>
<bean class="decodejava.Employee">
<property name="name" value="Emp2"></property>
<property name="telNo" value="222222"></property>
</bean>
<bean class="decodejava.Employee">
<property name="name" value="Emp3"></property>
<property name="telNo" value="333333"></property>
</bean>
</list>
</property>
</bean>
</beans>
Jul 21, 2018 3:06:54 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [config.beans.xml]
Name of employee : Emp1
Employee telephone num : 111111
Name of employee : Emp2
Employee telephone num : 222222
Name of employee : Emp3
Employee telephone num : 333333
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement