springboot-starter-parent的版本需要和Mybatis对应,否则会出现bean注册不成功Mapper找不到的情况,成功使用的版本如下:

 <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.1.3</version>
  </parent>
  
  <dependencies>
  
<!--    web依赖-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    
<!--    mybatis依赖-->
    <dependency>
      <groupId>org.mybatis.spring.boot</groupId>
      <artifactId>mybatis-spring-boot-starter</artifactId>
      <version>3.0.0</version>
    </dependency>
    
<!--    mysql依赖-->
    <dependency>
      <groupId>com.mysql</groupId>
      <artifactId>mysql-connector-j</artifactId>
    </dependency>
    
<!--      validation依赖-->
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-validation</artifactId>
      </dependency>
      
<!--      lombok依赖-->
      <dependency>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
      </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

当项目启动时报错,那大概率是maven依赖的对应版本出了问题,需要去官方查看对应版本。

当然,注册为bean的Mapper找不到本质是注解出了问题,Mapper没有被成功装入容器,也可以尝试在springboot启动类加上@MapperScan(value = "类名")

/**
 * Hello world!
 *
 */
@SpringBootApplication
//@ComponentScan(value = "com.atguigu.controller")
//@ComponentScan(value = "com.atguigu.mapper")
//@ComponentScan(value = "com.atguigu.service")
@MapperScan(value = "com.atguigu.mapper")
public class BigEventApplication {
    public static void main( String[] args ) {
        SpringApplication.run(BigEventApplication.class,args);
    }
}

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐