很呆的一个问题:我的新项目又找不到mapper这个bean了

1.选springboot版本

<properties>
        <java.version>8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <spring-boot.version>2.6.13</spring-boot.version>
    </properties>

2.加依赖

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-spring-boot3-starter</artifactId>
            <version>3.5.5</version>
        </dependency>

3.配yml

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/stu?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8
    username: root
    password: root

4.写mapper

@Mapper
public interface UserMapper extends BaseMapper<User> {
}

 

好了,接下来该报错了:找不到mapper里的bean

复制代码
Description:

Field userMapper in com.security.service.UserService required a bean of type 'com.security.mapper.UserMapper' 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.security.mapper.UserMapper' in your configuration.
复制代码
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.security.test.MapperTest': Unsatisfied dependency expressed through field 
'userMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.security.mapper.UserMapper' available: expected
at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

 

——————————

原因出在第一第二步:我选的是springboot2,导入pom依赖却来了个springboot3的mp

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.5</version>
        </dependency>

修改pom依赖即可,想不到我在一年之后又遇到了这种弱智问题 :-(  安详的死了

posted @   天启A  阅读(188)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话
点击右上角即可分享
微信分享提示