在service层中使用注解测试没有问题
但是在controller层不能注入
11-Sep-2020 13:25:49.601 严重 [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.servlet.FrameworkServlet.initServletBean Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'itemsController':
Unsatisfied dependency expressed through field 'itemsService';
nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.itheima.ssm.service.ItemsService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
controller中的配置文件
解决方法:
在controller中的配置文件
组件扫描调大一级后就能运行成功
原因分析:
分层开发后:maven会把controller相互依赖得层打成jar包放入到controller中
所以自我分析原因是:
把相互依赖得层打成jar包后controller得组件扫描不能扫描到spring容器中得service层,所以把controller调大一级后能注入service