• SpringBoot整合mybatisPlus-代码生成器错误和yaml常见错误


    SpringBoot整合MyBatis错误总结

    背景:4月5号中午,终于学完了SpringBoot的基本路线!休息几个小时,趁机会把SpringBoot的踩坑出坑记录一下

    ps: 大神勿喷

     

     


     

    错误:

    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'articleServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.xx.blog.mapper.ArticleMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

     
     

    错误场景:使用mybatisPlus代码生成器,通过数据库逆向生成代码。导致代码报错

    解决方案:

    在生成的 mapper 接口上添加注解@Mapper 或 在启动类上添加注解 @MapperScan("mapper包名")

     

    或者

     

    推荐:

    推荐在SpringBoot的启动类上添加注解@MapperScan("mapper包名") 一劳永逸 不然需要在所有的mapper接口上添加注解 @Mapper

     

     

     


       

     

     

    错误:

    Description:

    A component required a bean of type 'com.xx.blog.mapper.ArticleMapper' that could not be found.

    Action:

    Consider defining a bean of type 'com.xx.blog.mapper.ArticleMapper' in your configuration.

    Process finished with exit code 0

     

    错误场景: 在解决上面的错误之后又出现的错误 , 组件需要找不到“com.xx.blog.mapper.ArticleMapper”类型的bean。

    解决方案:

    添加了@Mapper注解之后这个接口在编译时会生成相应的实现类

    需要注意的是:这个接口中不可以定义同名的方法,因为会生成相同的id

    也就是说这个接口是不支持重载的 

     

     


     

     

     


     
     
     
     

    错误 :

    java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml

    错误场景:application.yml 就是一个大坑,如果出现以上情况,一般就是application.yml这个文件中有语法错误。

    解决方案:

    注释错误引起(application.yml采用的是#注释而不是//,而且# 后面必须跟一个空格)

    缩进采用空格,千万不要用tab

    每个冒号后面一定要有一个空格否则会报错

     

     

  • 相关阅读:
    [读书笔记]-大话数据结构-4-栈与队列(二)-队列
    [读书笔记]-大话数据结构-4-栈与队列(一)-栈、共享栈和链栈
    [读书笔记]-大话数据结构-3-线性表(二)-线性表的链式存储
    [读书笔记]-大话数据结构-3-线性表(一)-线性表的顺序存储
    [读书笔记]-大话数据结构-2-算法
    [读书笔记]-大话数据结构-1-数据结构绪论
    Linux Shell脚本教程:30分钟玩转Shell脚本编程(笔记)
    scikit-learn学习
    xampp启动遇到的小问题
    选项卡小结
  • 原文地址:https://www.cnblogs.com/kkdaj/p/12638909.html
Copyright © 2020-2023  润新知