简单的参数注入

来源:互联网 发布:员工网络 访客网络 编辑:程序博客网 时间:2024/05/16 14:47
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"?><beansxmlns="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 {@Testpublic void testOne(){ApplicationContext appl=new ClassPathXmlApplicationContext("beans_2.xml");StudentService service=(StudentService)appl.getBean("S_service");service.show();}}


 

原创粉丝点击