Spring学习-构造器注入

来源:互联网 发布:360电脑软件管家 编辑:程序博客网 时间:2024/05/08 21:12

在java里面构造带参数的构造器

package service.impl;import service.PersonService;import dao.PersonDAO;public class PersonServiceImpl1 implements PersonService{private PersonDAO personDao;private String name;private Integer id;public PersonServiceImpl1(PersonDAO personDao, String name, Integer id) {super();this.personDao = personDao;this.name = name;this.id = id;}/*public PersonServiceImpl1() {super();}*/@Overridepublic void save() {System.out.println(name+"-------------"+id);personDao.add();}}


<!-- 使用构造器注入 --><bean id="ss1" class="service.impl.PersonServiceImpl1">     <constructor-arg index="0" type="dao.PersonDAO" ref="personDao"/>     <constructor-arg index="1"  value="易家享"/>     <constructor-arg index="2"  value="99"/></bean><bean id="personDao" class="dao.impl.PersonDaoImpl"></bean>

type是构造器里面元素的类型 <constructor-arg index="" type="">

0 0
原创粉丝点击