public class StudentService {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public void show(){
System.out.println("name:"+name+" age:"+age);
}
}
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="S_service" class="com.sl.service.StudentService">
<property name="name" value="xiao hong"></property>
<property name="age">
<value>18</value>
</property>
</bean>
</beans>
public class test {
@Test
public void testOne(){
ApplicationContext appl=new ClassPathXmlApplicationContext("beans_2.xml");
StudentService service=(StudentService)appl.getBean("S_service");
service.show();
}
}