1.构造器注入
@Service
public class TestService implements IService{
private AService aService;
/**
* 如果该类只有一个构造方法,可省略@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;
}
网友评论