當(dāng)前位置:
                    首頁(yè) >
                            前端技术
>                            javascript
>内容正文                
                        
                    javascript
SpringBoot启动报错Consider defining a bean of type ‘com.test.springmvc.dao.xx‘ in your configuration.
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                SpringBoot启动报错Consider defining a bean of type ‘com.test.springmvc.dao.xx‘ in your configuration.
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.                        
                                報(bào)錯(cuò)信息如下:
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.報(bào)錯(cuò)截圖:
項(xiàng)目目錄結(jié)構(gòu):
SpringBootApplication啟動(dòng)類和controller、service、dao包同一級(jí)才能掃描到
 在保證目錄結(jié)構(gòu)沒(méi)問(wèn)題的情況下:
1.檢查自己的依賴MyBatis相關(guān)依賴是否齊全
<?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并檢查對(duì)應(yīng)的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是否添加了對(duì)用的注解。尤其是dao接口上的注解,要加上@Mapper這個(gè)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 {/*** 查詢?nèi)縐ser** @return*/List<User> findALL();/*** 根據(jù)id查詢User** @param id* @return*/User findById(int id);/*** 新增User** @param user* @return*/Integer addUser(User user);/*** 根據(jù)id刪除** @param id* @return*/Integer delUserById(int id);/*** 修改User** @param user* @return*/Integer updateUser(User user);}總結(jié)
以上是生活随笔為你收集整理的SpringBoot启动报错Consider defining a bean of type ‘com.test.springmvc.dao.xx‘ in your configuration.的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
 
                            
                        - 上一篇: 宇视网络视频录像机添加摄像机常规方法
- 下一篇: 计算机浏览器无法上网怎么办,电脑浏览器上
