部分错误代码
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private cn.xw.service.UserService cn.xw.controller.UserController.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [cn.xw.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:571)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 37 more
1 。service 层实现类 需要将当前类注释为一个spring的bean,名字是userService
2. 控制器层(controller)
@Autowired :自动注入服务层的Service对象
@Qualifier: 指明要注入的具体类型---(我之前没指明类型,所以报的错)
3. applicationContext.xml
mybatis:scan会将cn.xw.mapper包里的所有接口当作mapper配置,之后可以自动引入mapper类
扫描cn.xw包下面的java文件,有Spring的相关注解的类,则把这些类注册为Spring的bean
ok,其他的配置,都一样。
错误解决。