Spring No unique bean of type

泄露秘密 提交于 2019-12-05 03:01:08

That's one of the most basic concepts of Spring - Inversion of Control.

You don't need to declare your dependencies using their implementation types (to avoid coupling with implementation). You can declare them using interfaces or superclasses instead, and make Spring find the proper implementation class in the context.

In other words, bean are not distinguished by their implementation classes, because you may want to change implementation class of a bean without changing the beans that depend on it. If you want to distinguish between different beans of the same type, use logical bean names instead:

@Autowired @Qualifier("smartCardWrapper")
private SmartCardWrapper smardCardWrapper;

@Autowired @Qualifier("dummySmartCardWrapper")
private SmartCardWrapper dummySmardCardWrapper;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!