package com.amitsoft.test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.amitsoft.beans.EmployeeBean;
public class Test {
public static void main(String[] args)
{
ApplicationContext context = new ClassPathXmlApplicationContext("applicationcontext.xml"); //created container and linked to xml
EmployeeBean emp = (EmployeeBean)context.getBean("empbean"); // it returns Object--so typecast to respective class
//emp.setName(name); -- do these in xml <property>
//emp.setCity(city);
//emp.setSalary(salary);
String city = emp.getCity();
String name = emp.getName();
double sal = emp.getSalary();
System.out.println("Name: "+name+" || City: "+city+" || Salary: "+sal);
}
}
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.amitsoft.beans.EmployeeBean;
public class Test {
public static void main(String[] args)
{
ApplicationContext context = new ClassPathXmlApplicationContext("applicationcontext.xml"); //created container and linked to xml
EmployeeBean emp = (EmployeeBean)context.getBean("empbean"); // it returns Object--so typecast to respective class
//emp.setName(name); -- do these in xml <property>
//emp.setCity(city);
//emp.setSalary(salary);
String city = emp.getCity();
String name = emp.getName();
double sal = emp.getSalary();
System.out.println("Name: "+name+" || City: "+city+" || Salary: "+sal);
}
}
======================================================================
package com.amitsoft.beans;
public class EmployeeBean
{
private String name;
private String city;
private double salary;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
=======================================================================
<?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 ="empbean" class="com.amitsoft.beans.EmployeeBean">
<property name="name" value="Amit"></property>
<property name="city" value="Ranchi"></property>
<property name="salary" value="500000"></property>
</bean>
</beans>
No comments:
Post a Comment