最近在使用springboot整合mybatis-plus時遇到@Autowired失效問題,致使容器沒法啓動html
項目結構以下:spring
啓動類LsTestApplication:express
控制器UserController:springboot
實現類UserServiceImpl:mybatis
UserMapper:app
啓動以後一直報錯,報錯信息以下:ide
2019-08-23 17:16:16.457 WARN 8528 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.sand.demo.mapper.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}工具
猜想:開發工具
一、多是組件沒掃描到,相應的組件未加註解ui
二、啓動類不在掃描包的根目錄下也會致使bean註冊失敗
使用IDEA開發工具查看組件是有的,因此以上兩種可能都排除了
那就只剩下一種可能了,架包引用錯了,查看pom文件發現引用的是mybatis-plus依賴,
根據提供的文檔https://mp.baomidou.com/guide/install.html#release,springboot項目應該引用mybatis-plus-boot-starter這個依賴
而後記得將mapper掃描路徑加上,問題就解決了