1.springmvc中,一个接口有多个实现类,在controller中进行service注入后,程序能运行吗,原因是什么?
不能运行,运行时会报异常:No unique bean of type [com.test.service.EmployeeService] is defined: expected single matching bean but found 2。
原因是用@Autowired进行自动注入时,该接口只能有一个实现类,如果有多个,程序在进行方法调用时就会产生分歧,就会报错。
解决办法:指定注入的实现类。首先在@service("timeFilter"),在进行注入时,通过这两个注解添加名字进行进行指定实现类的实现。 @Autowired @Qualifier("timeFilter")
转载:附Autowired与Qualifier的区别与使用两者的区别与使用
2.