环境:jdk1.8,springboot
@Component public class ServiceOne { public String one(){ return "one"; } } |
@Component public class ServiceTwo { public String two(){ return "two"; } } |
1、构造器注入
@Component public class ServiceType { public static ServiceOne one; public static ServiceTwo two; @Autowired public ServiceType(ServiceOne one, ServiceTwo two) { this.one = one; this.two= two; } }
2、set注入
@Component public class ServiceTypeUtil { public static ServiceOne one; public static ServiceTwo two; @Autowired public void setServiceTwo(ServiceTwo two) { ServiceTypeUtil.two = two; } @Autowired public void setServiceOne(ServiceOne one) {