接口与自动注入
有业务接口 IService
和两种业务逻辑的实现 Aservice
, Bservice
如下:
public interface IService {}
@Component
public class Aservice implements IService {}
@Component
public class Bservice implements IService {}
采用下面的方式自动注入时,会报错:
public class ManageService {
@Autowired
private Aservice aservice;
@Autowired
private Bservice bservice;
// ...
}
异常信息类似为:nested exception is java.lang.IllegalArgumentException: Can not set xxx.ManageService field xxx.ManageService.aservice to com.sun.proxy.$Proxy48