SpringBoot项目运行错误:找不到CourseMapper Bean,文件存在,路径也正确,还会是什么原因导致的呢?-灵析社区

CO_co

![这是我的目录](https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241003/e83f794ebdc3ca10ec81a4cb4601d8dd.png) Description: Field courseMapper in com.ztt.bootest.service.impl.CourseServiceImpl required a bean of type 'com.ztt.bootest.mapper.CourseMapper' that could not be found. The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true) Action: Consider defining a bean of type 'com.ztt.bootest.mapper.CourseMapper' in your configuration. 以上是我的报错信息, 这是我的xml spring.application.name=BootTest server.port=8082 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/ktp_db?autoReconnect=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8 spring.datasource.username=root spring.datasource.password=123456 mybatis.mapper-locations=classpath:mapper/*Mapper.xml mybatis.type-aliases-package=com.ztt.bootest.entity spring.thymeleaf.check-template=false spring.thymeleaf.check-template-location=false mybatis.configuration.map-underscore-to-camel-case=true 这是我的application.properties 这是我自写的一个MyBatis+SpringBoot项目,不知道为什么运行不了,csdn上面的方法我试过了,都解决不了,总感觉是自己哪步比较关键的步骤弄错了,但是自己发现不了 希望哪位大佬帮我发现一下我的错误

阅读量:110

点赞量:0

问AI
看报错是 "CourseMapper" 没有被注册成为一个bean啊,试试以下两步 1.在启动类加上注解 @MapperScan("com.ztt.bootest.mapper") 2.在 "CourseMapper" 这个类上加上 "@Repository" 注解