package com.edu;
public class HelloBean {
private String name;
private String course;
private Double score;
public HelloBean(String name, String course, Double score) {
super();
this.name = name;
this.course = course;
this.score = score;
}
public HelloBean() {
super();
// TODO Auto-generated constructor stub
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCourse() {
return course;
}
public void setCourse(String course) {
this.course = course;
}
public Double getScore() {
return score;
}
public void setScore(Double score) {
this.score = score;
}
public void show() {
String s="姓名: "+this.getName()+" 课程名:"+this.getCourse()+" 成绩:"+this.getScore();
System.out.println(s);
}
}
<?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-3.2.xsd">
<bean name="stu1" class="com.edu.HelloBean">
<property name="name" value="张三"></property>
<property name="course" value="数学"></property>
<property name="score" value="95"></property>
</bean>
<bean name="stu2" class="com.edu.HelloBean">
<property name="name" value="里斯"></property>
<property name="course" value="物理"></property>
<property name="score" value="90"></property>
</bean>
<bean name="stu3" class="com.edu.HelloBean">
<property name="name" value="王五"></property>
<property name="course" value="语文"></property>
<property name="score" value="85"></property>
</bean>
</beans>
package com.edu;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class main {
public static void main(String[] args) {
ApplicationContext act=new ClassPathXmlApplicationContext("springjava.xml");
HelloBean student;
student=(HelloBean) act.getBean("stu1");
student.show();
student=(HelloBean) act.getBean("stu2");
student.show();
student=(HelloBean) act.getBean("stu3");
student.show();
}
}