一个简单跟着网上打的后端程序,控制台报错Spring无法找到UserMapper的Bean定义,导致userServiceImpl无法注入baseMapper。2025-04-08T16:20:29.450+08:00 ERROR 25760 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'controller': Unsatisfied dependency expressed through field 'userService': Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'baseMapper': No qualifying bean of type 'com.example.wms.mapper.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
项目结构为
.gitattributes
│ .gitignore
│ HELP.md
│ mvnw
│ mvnw.cmd
│ pom.xml
│
├─.mvn
│ └─wrapper
│ maven-wrapper.properties
│
├─src
│ ├─main
│ │ ├─java
│ │ │ └─com
│ │ │ └─example
│ │ │ └─wms
│ │ │ │ WmsApplication.java
│ │ │ │
│ │ │ ├─controller
│ │ │ │ Controller.java
│ │ │ │
│ │ │ ├─entity
│ │ │ │ User.java
│ │ │ │
│ │ │ ├─mapper
│ │ │ │ UserMapper.java
│ │ │ │
│ │ │ └─service
│ │ │ │ UserService.java
│ │ │ │
│ │ │ └─impl
│ │ │ UserServiceImpl.java
│ │ │
│ │ └─resources
│ │ │ application.yml
│ │ │
│ │ ├─static
│ │ └─templates
│ └─test
│ └─java
│ └─com
│ └─example
│ └─wms
│ WmsApplicationTests.java
│
└─target
├─classes
│ │ application.yml
│ │
│ └─com
│ └─example
│ └─wms
│ │ WmsApplication.class
│ │
│ ├─controller
│ │ Controller.class
│ │
│ ├─entity
│ │ User.class
│ │
│ ├─mapper
│ │ UserMapper.class
│ │
│ └─service
│ │ UserService.class
│ │
│ └─impl
│ UserServiceImpl.class
│
└─generated-sources
└─annotations
不知道错在哪里,更着网上各种教程越改越乱。一个简单的程序出的错应该不是很大。问问有经验的人具体错哪了。
mp依赖错了,添加的支持不了spring3
WmsApplication 类加一下 @MapperScan("com.example.wms.mapper") 试试
已经解决了,是由于mp3.4和spring boot3不兼容,换成3.5就行了