@Service public class A extends GenericBaseService { @Autowired private B b; } @Service public class B extends GenericBaseService { @Autowired private A a; } //如上代码所描述,启动时可能会报循环依赖的错误(并非一定会报错),如果报错的话,就是spring不知道应该先加载哪个类先了,好比,有蛋才有鸡和有鸡才有蛋的问题,解决方案是,如果先有蛋
.net实现依赖注入 1. 问题的提出 开发中,尤其是大型项目的开发中,为了降低模块间.类间的耦合关系,比较提倡基于接口开发,但在实现中也必须面临最终是“谁”提供实体类的问题.Martin Fowler在<Inversion of Control Containers and the Dependency Injection pattern>中也提到了标准的三种实现方式——Constructor Injection.Setter Injection和Interface Injection,很全