出现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);
    }
}
相关文章
|
11月前
|
虚拟化
成功解决Failed to execute stage ‘Setup validation’: Hardware does not support virtualization.
成功解决Failed to execute stage ‘Setup validation’: Hardware does not support virtualization.
|
11月前
|
Java Apache Spring
解决required a single bean, but 2 were found问题
背景:springboot整合shiro中自定义Realm时出现 错误描述 Parameter 0 of method getDefaultWebSecurityManager in cn.ken.springboot_shiro.config.ShiroConfig required a single bean, but 2 were foun
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
969 0
Error starting ApplicationContext. To display the conditions report re-run your application with
报错解决:Reason: Failed to determine a suitable driver class
报错解决:Reason: Failed to determine a suitable driver class
2489 0
报错解决:Reason: Failed to determine a suitable driver class
一零五、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
|
应用服务中间件 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:
115 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
When should reread of cl_crm_bol_entity and $scope.$apply be called manually
When should reread of cl_crm_bol_entity and $scope.$apply be called manually
129 0
When should reread of cl_crm_bol_entity and $scope.$apply be called manually
A BRIEF INTRODUCTION TO STATISTICS | DEFINITION, SCOPE AND LIMITATIONS
Introduction to Statistics: In the modern world of computers and information technology, the importance of statistics is very well recognized by all the disciplines.
1405 0