Description: Field ud in com.yjj.service.impl.UserServiceImpl required a bean of type 'com.yjj.dao.UserDao' that could not be found. Action: Consider defining a bean of type 'com.yjj.dao.UserDao'


這是在用springboot時遇到的error

Description:

Field ud in com.yjj.service.impl.UserServiceImpl required a bean of type 'com.yjj.dao.UserDao' that could not be found.

Action:

Consider defining a bean of type 'com.yjj.dao.UserDao' in your configuration.

原因:

我找到的一種原因是在mappers文件夾下的mapper.xml文件沒有掃到com.yjj.dao這個包

所以要在Application(啟動類)上加上

@MapperScan("com.yjj.dao")注解

代碼如下:
package com.yjj.bootdemo01;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages = {"com.yjj.dao","com.yjj.service","com.yjj.controller"})
@MapperScan("com.yjj.dao") public class Bootdemo01Application {

    public static void main(String[] args) {
        SpringApplication.run(Bootdemo01Application.class, args);
    }

}

 

 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM