出现Error creating bean with name与CONDITIONS EVALUATION REPORT问题

简介: 出现Error creating bean with name与CONDITIONS EVALUATION REPORT问题

1.说明:


今天在学习mybatis-plus时候在做springboot测试用例,运行测试用例报红。出现CONDITIONS EVALUATION REPORT。


这个不是主要原因,直到找到下面报错信息:Error creating bean with name 'com.example.mybatisplusself.MybatisPlusTest': Unsatisfied dependency expressed through field 'userMapper'; 说我没有配置bean。


image.png


image.png


2.解决:


找了很多资料,后来认为是创建bean,可能是@MapperScan注解错误,结果真的是,粘贴路径时候粘贴错了,@MapperScan注解中的路径扫描的都是包而不是类,我的UserMapper是mapper类,所以根本没有UserMapper包,根本没有扫描到mapper类。


改为:就解决了,扫描mapper所在包的位置。


@MapperScan("com.example.mybatisplusself.mapper")


image.png

3.补充


这里在说一下@Mapper注解与@MapperScan注解。


1、@Mapper注解:

作用:在接口类上添加了@Mapper,在编译之后会生成相应的接口实现类。


添加位置:接口类上面。


@Mapper
public interface UserMapper {
//代码
}

如果想要每个接口都要变成实现类,那么需要在每个接口类上加上@Mapper注解,比较麻烦,解决这个问题用@MapperScan。


2、@MapperScan

作用:指定要变成实现类的接口所在的包,然后包下面的所有接口在编译之后都会生成相应的实现类


添加位置:是在Springboot启动类上面添加,


image.png


添加@MapperScan(“com.peach.mapper”)注解以后,com.example.mybatisplusself.mapper包下面的接口类,在编译之后都会生成相应的实现类.


3、使用@MapperScan注解多个包

(实际用的时候根据自己的包路径进行修改)


@SpringBootApplication
@MapperScan({“com.kfit.demo”,“com.kfit.user”})
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}
4、 如果dao接口类没有在Spring Boot主程序可以扫描的包或者子包下面,可以使用如下方式进行配置:
(没验证过,不确定能否使用,或许需要根据自己定义的包名进行修改路径)
@SpringBootApplication
@MapperScan({“com.kfit..mapper","org.kfit..mapper”})
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}
相关文章
|
5月前
|
Kubernetes 容器
error: no configuration has been provided, try setting KUBERNET
error: no configuration has been provided, try setting KUBERNET
59 0
|
2月前
|
编译器 API C++
【Matlab】解决使用Mex 报错There was a problem creating the mex file for Real Time Execution ,Please ensure y
解决Matlab使用Mex时出现的"Real Time Execution"错误的步骤,即通过安装"MATLAB 支持 MinGW-w64 C/C++ 编译器"这个包来确保编译器设置正确。
46 0
|
5月前
|
JavaScript 程序员 Swift
The compiler is unable to type-check this expression in reasonable time; try breaking up the express
The compiler is unable to type-check this expression in reasonable time; try breaking up the express
65 0
|
5月前
解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
97 5
|
虚拟化
成功解决Failed to execute stage ‘Setup validation’: Hardware does not support virtualization.
成功解决Failed to execute stage ‘Setup validation’: Hardware does not support virtualization.
|
5月前
|
安全 Java 应用服务中间件
A configuration error occurred during startup.Please verify the preference field with the prompt: To
A configuration error occurred during startup.Please verify the preference field with the prompt: To
|
SQL Oracle 关系型数据库
Troubleshooting: Missing Automatic Workload Repository (AWR) Snapshots and Other Collection Issues (Doc ID 1301503.1)
Troubleshooting: Missing Automatic Workload Repository (AWR) Snapshots and Other Collection Issues (Doc ID 1301503.1)
739 0
|
应用服务中间件 Android开发
a configuration error occurred during startup. place verify the preference field whth the prompt:TomcatJDK name:
a configuration error occurred during startup. place verify the preference field whth the prompt:TomcatJDK name:
131 0
a configuration error occurred during startup. place verify the preference field whth the prompt:TomcatJDK name:
SAP MM Error message - Customizing incorrectly maintained – in transaction code ML81N
SAP MM Error message - Customizing incorrectly maintained – in transaction code ML81N
SAP MM Error message - Customizing incorrectly maintained – in transaction code ML81N
How is note created - backend implementation
Created by Wang, Jerry, last modified on Jan 15, 2015
How is note created - backend implementation