在impl中加了serviece注解,启动服务时
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'brandController': Injection of resource dependencies failed; nested exception is
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of
type '?' available: expected single matching bean but found 2:
brandServiceImpl,categoryServiceImpl
删除impl中service注解,运行还不报错
更厉害的是 使用controller的mapper还可以使用
错误的原因是:
@Autowired和 @Resource的区别
由于在继承的基类 BaseController中,自动注入的是service,虽然下面有红色波浪线,但是并不影响运行
错误原因是:将@Autowired修改成了@Resource,
因为其他实现类都是继承同一个ICrudService,只是实现类不同,需要使用Autowired,如果使用@Resource,需要标注上name
autowired是按照类型注入的,而resource是按照名字自动注入的(可以指定type注入)