1.構(gòu)造器注入
@Service
public class TestService implements IService{
private AService aService;
/**
* 如果該類只有一個(gè)構(gòu)造方法,可省略@Autowired
**/
@Autowired
public AService(AService aService){
this.aService = aService;
}
}
2.setter方法注入
@Service
public class TestService implements IService{
private AService aService;
public void setAService(AService aService){
this.aService = aService;
}
}
3.屬性方法注入
@Service
public class TestService implements IService{
@Autowired
private AService aService;
}