出现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);
    }
}
相关文章
|
虚拟化
成功解决Failed to execute stage ‘Setup validation’: Hardware does not support virtualization.
成功解决Failed to execute stage ‘Setup validation’: Hardware does not support virtualization.
|
9月前
|
安全 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
Error: Plugin/Preset files are not allowed to export objects, only functions……
Error: Plugin/Preset files are not allowed to export objects, only functions……
|
网络协议 关系型数据库 Linux
onfigure: error: no acceptable C compiler found in $PATH See `config.log' for more details 问题解决
onfigure: error: no acceptable C compiler found in $PATH See `config.log' for more details 问题解决
204 0
Error starting ApplicationContext. To display the conditions report re-run your application with
Error starting ApplicationContext. To display the conditions report re-run your application with
1076 0
Error starting ApplicationContext. To display the conditions report re-run your application with
|
应用服务中间件 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:
151 0
a configuration error occurred during startup. place verify the preference field whth the prompt:TomcatJDK name:
一零五、Error starting ApplicationContext. To display the conditions report re-run your application with
一零五、Error starting ApplicationContext. To display the conditions report re-run your application with
一零五、Error starting ApplicationContext. To display the conditions report re-run your application with
|
Oracle 安全 关系型数据库
IMP-00041: Warning: object created with compilation warnings
<p><br></p> <p><strong style="background-color:rgb(255,255,0)"><span style="font-size:14px; color:#ff0000">IMP-00041: Warning: object created with compilation warnings</span></strong><br></p> <p
4719 0