Advertisement
package decodejava;
public class EmployeeAccounts
{
private Employee employee;
private int balance;
private String account_Id;
public String getAccount_Id()
{
return account_Id;
}
public void setAccount_Id(String account_Id)
{
this.account_Id = account_Id;
}
public Employee getEmployee()
{
return employee;
}
public void setEmployee(Employee employee)
{
this.employee = employee;
}
public int getBalance()
{
return balance;
}
public void setBalance(int balance)
{
this.balance = balance;
}
}
package decodejava;
public class Employee
{
private int id;
private String name;
private char positionGrade;
private float yearsOfExp;
static String message;
public void setId(int id)
{
this.id = id;
}
public int getId()
{
return id;
}
public float getYearsOfExp()
{
return yearsOfExp;
}
public void setYearsOfExp(float yearsOfExp)
{
this.yearsOfExp = yearsOfExp;
}
public char getPositionGrade()
{
return positionGrade;
}
public void setPositionGrade(char positionGrade)
{
this.positionGrade = positionGrade;
}
public String getName()
{
return name;
}
public String setName(String name)
{
this.name = name;
return this.name;
}
public static String getMessage()
{
return message;
}
public static void setMessage(String m)
{
message = m;
}
}
Advertisement
package decodejava;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
public class Utility {
public static void main(String[] args) throws NoSuchMethodException, SecurityException
{
ApplicationContext context = new FileSystemXmlApplicationContext("classpath:config.beans.xml");
EmployeeAccounts employeeAcc = context.getBean("EmployeeAccountsBean", EmployeeAccounts.class);
Employee emp = employeeAcc.getEmployee();
System.out.println("Employee's Name : " + emp.getName());
System.out.println("Employee's ID : " + emp.getId());
System.out.println("Employee's Position Grade : " + emp.getPositionGrade());
System.out.println("Employee's Years Of Exp : " + emp.getYearsOfExp());
System.out.println("Message for employee : " + emp.getMessage());
System.out.println("Employee's Balance : " + employeeAcc.getBalance());
System.out.println("Employee's ID : " + employeeAcc.getAccount_Id());
}
}
<?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="EmployeeBean" class="decodejava.Employee">
<property name="name" value="#{'Emp1'}"></property>
<property name="id" value="#{1}"></property>
<property name="positionGrade" value="#{'A'}"></property>
<property name="yearsOfExp" value="#{6.5}"></property>
<property name="message" value="#{'Best of luck!'}"></property>
</bean>
<bean id="EmployeeAccountsBean" class="decodejava.EmployeeAccounts">
<property name="employee" value="#{EmployeeBean}"></property>
<property name="balance" value="10000"></property>
<property name="account_Id" value="1001"></property>
</bean>
</beans>
Advertisement
Aug 24, 2018 5:29:14 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@1ee0005: startup date [Fri Aug 24 17:29:14 2018]; root of context hierarchy
Aug 24, 2018 5:29:14 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [config.beans.xml]
Employee's Name : Emp1
Employee's ID : 1
Employee's Position Grade : A
Employee's Years Of Exp : 6.5
Message for employee : Best of luck!
Employee's Balance : 10000
Employee's ID : 1001
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement