Spring学习——依赖注入

控制反转(IoC)又称为dependency injection(依赖注入),是spring核心的一部分。依赖注入分construtor injection,setter injection.

1.constuctor-arg injection

 

package com.mydomain;

public class Person {
private String name;
private int age;

public Person(String name, int age) {
this .name = name;
this .age = age;
}
}

bean配置

 

 

< bean id ="person" class ="com.mydomain.Person" >
< constructor-arg value ="Goodwin" ></ constructor-arg >
< constructor-arg value ="20" ></ constructor-arg >
</ bean >

接口注入也是构建起注入的一种

interface Service{
public String get();
public List
< T > list();
}

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(spring)