springboot @Bean创建容器失败如何解决 您所在的位置:网站首页 创建flash对象失败什么原因 springboot @Bean创建容器失败如何解决

springboot @Bean创建容器失败如何解决

2024-06-02 01:08| 来源: 网络整理| 查看: 265

一、大家先来看我的报错 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userController’: Unsatisfied dependency expressed through field ‘userService’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userServiceImpl’: Unsatisfied dependency expressed through field ‘userMapper’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userMapper’ defined in file [F:\springboot\target\classes\com\lty\springboot\mapper\UserMapper.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property ‘sqlSessionFactory’ or ‘sqlSessionTemplate’ are required 额。。。。。。 或许有点乱但是应该没啥关系,这段报错的意思就是告诉咱们,创建bean 容器userController 创建失败。一开始遇到这个我也是头皮发麻,心里一万个尼玛,太悲催了。不过,最终还是通过小铁的不懈努力终于解决了; 在这里插入图片描述

二、下面我先讲讲如何解决 1)检查pom.xml文件是否缺少依赖

com.alibaba druid-spring-boot-starter 1.1.10

2)检查你的application 没有在这个文件配置来映射的话,会找不到你的mapper文件

mybatis: mapper-locations: classpath:mapper/ *.xml type-aliases-package: com.lty.springboot.mapper

3)检查你的impl层是否添加了@service注解 在这里插入图片描述

4)检查你的启动类是否添加了@MapperScan注解 注意:里面的地址直接指到你的mapper 在这里插入图片描述 5)还有要检查你的启动类,一定要放在springboot(你的包)下面 别放错了,否则启动会找不到的 在这里插入图片描述 我的错误就是因为缺少了pom.xml 依赖一直找不到注解,不过还好找到了,真的好惨。 大家以后写代码要注意心细一些我感觉就不会报这种错误了,小铁也是为了自己的不细心买了1个小时的单。 如果经过以上的步骤还是报错,大家可以在底下留言。小铁看见的话 就会给大家解答,以上皆为自己总结,如果有误请见谅。

如果小铁的文章对大家有帮助的话,就请点个赞吧!!!

我是小铁,一个实力与逗比的结合体。 ——小铁



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有