Advertisement
package decodejava;
import java.util.List;
public class Company
{
public String name;
public Employee employeeArray[];
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public Employee[] getEmployeeArray()
{
return employeeArray;
}
public void setEmployees(Employee[] employeeArray)
{
this.employeeArray = employeeArray;
}
}
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);
Employee[] employeeArray = company.getEmployeeArray();
for(Employee emp : employeeArray)
{
System.out.println("Employee Name : " + emp.getName());
System.out.println("Employee Tel No : " + 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">
<array>
<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>
</array>
</property>
</bean>
</beans>
Jul 21, 2018 5:54:00 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [config.beans.xml]
Employee Name : Emp1
Employee Tel No : 111111
Employee Name : Emp2
Employee Tel No : 222222
Employee Name : Emp3
Employee Tel No : 333333
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement