依赖注入Dependency Injection,DI

依赖注入Dependency Injection,DI

@AutoWired,他注入的机制最基本的一条是:根据类型(by type),根据类型从IOC容器中获取bean。
使用AutoWired进行依赖注入的时候,如果注入的接口有多于一个的实现类,可一根据变量名称,从IOC容器中获取对象。
Animal接口 两个实现类:dog、cat
@AutoWired
Animal animal; // 报错
@AutoWired
Animal dog; // 正常 通过name从IOC容器中获取bean

你可能感兴趣的:(面试资料)