1.Spring怎么知道注入哪一个实现?
As long as there is only a single implementation of the interface and that implementation is annotated with @Component with Spring’s component scan enabled, Spring framework can find out the (interface, implementation) pair. If component scan is not enabled, then you have to define the bean explicitly in your application-config.xml (or equivalent spring configuration file).
若是Spring配置了component scan,而且要注入的接口只有一个实现的话,那么spring框架能够自动将interface于实现组装起来。若是没有配置component scan,那么你必须在application-config.xml(或等同的配置文件)定义这个bean。spring
2.须要@Qualifier和@Resource注解吗?
Once you have more than one implementation, then you need to qualify each of them and during auto-wiring, you would need to use the @Qualifier annotation to inject the right implementation, along with @Autowired annotation. If you are using @Resource (J2EE semantics), then you should specify the bean name using the name attribute of this annotation.
一旦一个接口有多个实现,那么就须要每一个特殊化识别而且在自动装载过程当中使用@Qualifier和@Autowired一块儿使用来标明。若是是使用@Resource注解,那么你应该使用resource中属性名称来标注@Autowired.app