报错信息如下:

Description:Field userDao in com.test.springmvc.service.impl.UserServiceImpl required a bean of type 'com.test.springmvc.dao.UserDao' 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.test.springmvc.dao.UserDao' in your configuration.

报错截图:

项目目录结构:

SpringBootApplication启动类和controller、service、dao包同一级才能扫描到
在保证目录结构没问题的情况下:

1.检查自己的依赖MyBatis相关依赖是否齐全

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.6.0</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.test</groupId><artifactId>springmvc</artifactId><version>0.0.1-SNAPSHOT</version><name>springmvc</name><description>SpringMVCPractice</description><properties><java.version>1.8</java.version></properties><dependencies><!--MyBatis--><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>1.3.2</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.13</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.1.10</version></dependency><!--lombok--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>2.6.0</version></dependency></dependencies></project>

2.配置文件是否配置了jdbc信息和MyBatis的别名和包扫描

#端口
server.port=8080#jdbc配置
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/testdb09?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root#MyBatis
mybatis.mapper-locations=classpath:com/test/dao/*.xml
mybatis.type-aliases-package=com.test.domain

并检查对应的Mapper文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.test.springmvc.dao.UserDao"><select id="findALL" resultType="com.test.springmvc.domain.User">select *from user</select><select id="findById" resultType="com.test.springmvc.domain.User">select *from userwhere id=#{id}</select><insert id="addUser">insert into user (name,age)values (#{name},#{age})</insert><delete id="delUserById">deletefrom  userwhere id=#{id}</delete><update id="updateUser">update userset name=#{name},age=#{age}where id=#{id}</update></mapper>

3.最后查看controller、service和dao是否添加了对用的注解。尤其是dao接口上的注解,要加上@Mapper这个ibatis的注解

package com.test.springmvc.dao;import com.test.springmvc.domain.User;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;import java.util.List;@Repository
@Mapper
public interface UserDao {/*** 查询全部User** @return*/List<User> findALL();/*** 根据id查询User** @param id* @return*/User findById(int id);/*** 新增User** @param user* @return*/Integer addUser(User user);/*** 根据id删除** @param id* @return*/Integer delUserById(int id);/*** 修改User** @param user* @return*/Integer updateUser(User user);}

SpringBoot启动报错Consider defining a bean of type ‘com.test.springmvc.dao.xx‘ in your configuration.相关推荐

  1. springboot启动报错CommentService required a bean of type ‘com.xxx.xxx.dao.CommentMapper‘ that could not

    Description: Field commentMapper in com.xxx.xxx.service.CommentService required a bean of type 'com. ...

  2. springboot启动报错: Consider defining a bean of type ‘XXX‘ in your configuration

    Consider defining a bean of type 'XXX' in your configuration 出现这个错误,要看看你是否用到了某些组件,但是启动类上没加相应的注解.比如说我 ...

  3. SpringCloud - 整合Nacos启动报错Consider defining a bean of type IClientConfig

    SpringCloud - 整合Nacos启动报错Consider defining a bean of type IClientConfig 前言 一. 尝试解决Bug的几种不合适方案 1.1 添加 ...

  4. 解决启动报错Consider defining a bean of type ‘xxx‘ in your configuration.

    解决启动报错Consider defining a bean of type 'xxx' in your configuration. 报错截图 解决方法:查看注解是否同时存在@AllArgsCons ...

  5. Spring Cloud/Boot启动报错Consider defining a bean of type ServerCodecConfigurer

    网关项目启动报错内容如下: Error starting ApplicationContext. To display the conditions report re-run your applic ...

  6. 【微服务】 网关启动报错 Consider defining a bean of type org.springframework.http.codec.ServerCodecConfigurer

    一.现象 微服务启动时报错:Consider defining a bean of type 'org.springframework.http.codec.ServerCodecConfigurer ...

  7. springboot 启动报错:required a bean of type 'xxxRepository' that could not be found

    springboot启动的时候报错,错误如下: Field demoRepository in com.ge.serviceImpl.DemoServiceImpl required a bean o ...

  8. SpringBoot Consider defining a bean of type 'com.xxx.xxx.dao.UserDao' in your configuration.

    SpringBoot 遇到的问题 遇到错误提示 required a bean of type 'com.xxx.xxx.dao.UserDao' that could not be found. 但 ...

  9. 学习记录报错Consider defining a bean of type ‘org.springframework.web.client.RestTemplate‘ in your configu

    springboot启动就报错 信息如下 Field restTemplate in com.atguigu.springcloud.controller.OrderController requir ...

最新文章

  1. 后盾网lavarel视频项目---3、lavarel中子控制器继承父控制器以判断是否登录
  2. 原创:E325: ATTENTION vim超完整超给力的问题与解决方法
  3. 在websphere部署完war包后出现com.ibm.ws.jsp.JspCoreException: JSPG0218E异常
  4. 基于vue2.0打造移动商城页面实践 vue实现商城购物车功能 基于Vue、Vuex、Vue-router实现的购物商城(原生切换动画)效果...
  5. mysql 事务 异常_mysql事务级别以及相应的异常现象
  6. 蓝桥杯 第几个幸运数 set
  7. 开放源代码机器人控制软件
  8. 三层交换机和链路聚合
  9. CSS世界Bug般的存在——字母x与“居中”
  10. 中华石杉Java面试突击第一季笔记二(分布式搜索引擎)
  11. u检验中的查u界值表_u检验和t检验
  12. 【idea drools 执行20次失败中断崩溃】
  13. 杭州电子科技大学研究生计算机科学与技术,杭州电子科技大学-硕士研究生-计算机学院 2018级计算机科学与技术(中日合作)培养方案...
  14. java 表格tr td_table、tr、td表格的行、单元格等属性说明
  15. 音乐考试分数计算机,音乐艺考分数怎么算 音乐艺考分数比例
  16. Java减肥高手Xtend 捆绑Eclipse IDE
  17. 微信小游戏-飞机游戏玩法改造系列(二:支持血条)
  18. 利用STM32F103最小系统做C2接口离线烧录器
  19. 如何实现电脑文件的自动备份?
  20. 我的深度学习的学习之旅

热门文章

  1. 计算机的发展经历起源与未来,计算机起源与发展历程.ppt
  2. java 与 汇编_清华大学出版社-图书详情-《汇编语言与计算机体系结构——使用C++和Java》...
  3. 区块链开发者观点:来自 Carbon 的 Nick Pai
  4. java双音频文件分频_分频电路作用,怎么来理解二分频电路?
  5. Java开发校招面试考点汇总
  6. 微果I7随身便携投影仪好不好用?和哈趣H1相比哪个更值得入手?
  7. Python基础入门知识(11)
  8. NAS系列 硬件选择
  9. 企业打造顶级研究院的最优路径是什么?
  10. 没有植入的内容就是TM在逗我