错误信息:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userService’: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.tulun.dao.UserMapper com.tulun.service.UserService.userMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.tulun.dao.UserMapper] 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)}
分析
报错大意是由于不能创建名为userService的bean而出错,又进一步指出userMapper类型的的bean没找到依赖。我们着重分析UserMapper.xml文件、UserService.java、UserController.java的里面的命名、注解、大小写之类的错误。
原因:
UserMapper.xml文件里 <?xml version="1.0" encoding="UTF-8" ?>
没有放在首行。一定要按格式写啊啊啊啊!!!!大家要引以为戒。