启动报错:

2018-05-16 17:22:58.161 ERROR 4080 --- Disconnected from the target VM, address: '127.0.0.1:50529', transport: 'socket'
[ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter : ***************************
APPLICATION FAILED TO START
*************************** Description: Field huaYangAreaMapper in com.sxd.swapping.service.impl.HuaYangServiceImpl required a bean of type 'com.sxd.swapping.dao.mybatis.HuaYangAreaMapper' that could not be found. Action: Consider defining a bean of type 'com.sxd.swapping.dao.mybatis.HuaYangAreaMapper' in your configuration.

解决方案:

根据错误提示

Mybatis的 Mapper类不能被找到,所以需要通过注解标明这个类可以给spring 管理并且给其他类调用的。

下面有两种方式提供:

方式1:使用@Mapper注解标注在Mapper类上

@Mapper
public interface HuaYangAreaMapper { @Select("SELECT * FROM hua_yang_area where uid = #{uid}")
@Results({
@Result(property = "areaName",column = "area_name",javaType = String.class),
@Result(property = "areaPerson",column = "area_person",javaType = Long.class),
@Result(property = "createId",column = "create_id",javaType = String.class)
})
HuaYangArea findOne(String uid); }

方式2:使用@MapperScan("mapper类所在包位置")

@SpringBootApplication
@MapperScan("com.sxd.swapping.dao.mybatis")
public class SwappingApplication { public static void main(String[] args) {
SpringApplication.run(SwappingApplication.class, args);
}
}

如果有多个包需要被扫描到,可以传入字符串数组

@MapperScan({"com.sxd.swapping.dao.mybatis","com.sxd.swapping.dao.mapper"})

上面这两种方式都可以使用。

====================================

至于@Mapper 和@MapperScan注解的区别,一个只需要在启动类配置一次,一个是需要在每个mapper上进行配置

【spring boot】mybatis启动报错:Consider defining a bean of type 'com.newhope.interview.dao.UserMapper' in your configuration. 【Mapper类不能被找到】@Mapper 和@MapperScan注解的区别的更多相关文章

  1. Spring boot&Mybatis 启动报错 Failed to auto-configure a DataSource

    *************************** APPLICATION FAILED TO START *************************** Description: Fai ...

  2. springboot 启动报错Consider defining a bean of type 'com.example.springbootdruid.mapper.UserMapper' in your configurati

    一.问题 springboot项目启动时报错: Field userMapper in com.example.springbootdruid.service.impl.UserServiceImpl ...

  3. Sping Cloud项目启动报A component required a bean of type 'com.tianyan.bbc.dao.SecurityUserBaseMapper' that could not be found.

    项目构建正常,启动和Debug报以下错误: Error starting ApplicationContext. To display the conditions report re-run you ...

  4. 创建spring boot项目启动报错遇到的问题

    1.Spring boot,Mybatis 启动报错 Failed to auto-configure a DataSource *************************** APPLICA ...

  5. 【spring boot Mybatis】报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.newhope.interview.dao.UserMapper.add

    报错如下: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.newhope.i ...

  6. spring cloud gateway网关启动报错:No qualifying bean of type 'org.springframework.web.reactive.DispatcherHandler'

    网关配置好后启动报错如下: org.springframework.context.ApplicationContextException: Unable to start web server; n ...

  7. IntelliJ IDEA 2017版 spring-boot 报错Consider defining a bean of type 'xxx' in your configuration问题解决方案

    问题分析: 通过问题的英文可知,这个错误是service的bean注入失败,那么为什么会产生这个问题呢? 主要是框架的Application产生的,所以我们建立项目的时候,要保证项目中的类跟Appli ...

  8. spring boot项目启动报错

    在eclipse中运行没有任何问题,项目挪到idea之后就报错 Unable to start EmbeddedWebApplicationContext due to miss EmbeddedSe ...

  9. spring 整合Mybatis 《报错集合,总结更新》

    错误:java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldExcepti ...

随机推荐

  1. 智能指针之 weak_ptr

    1. weak_ptr 介绍 std::weak_ptr 是一种智能指针,它对被 std::shared_ptr 管理的对象存在非拥有性("弱")引用.在访问所引用的对象指针前必须 ...

  2. Mac OSX: 有线共享WiFi

    首先连上有线 系统偏好设置->网络->点击左侧WiFi,再点击右下角[高级] 勾选[创建电脑对电脑网络],然后单击[好] 在顶部菜单栏击WiFi图标,如果WiFi未打开,则单击打开,如果已 ...

  3. 蓝牙学习(2)USB Adapter

    主要分析一下蓝牙USB Adapter使用USB接口传输HCI包的实现及过程. 参照上面的Bluetooth core system architecture图, 蓝牙USB Adapter作为Blu ...

  4. docker系列之网络配置

    docker 网络配置 docker 安装后, 会自动在系统做一个网桥配置 docker0 . 其容器都会分配到此网桥配置下的独立, 私有 IP 地址. 如果你要自己配置桥接, 也可以把 docker ...

  5. js对象,数组,字符串的操作

    循环绑定=>变量污染 for (var i = 0;i<lis.length;i++){ lis[i].index = i;#给页面元素对象添加一个任意属性(保留索引的属性index) # ...

  6. LeetCode(125) Valid Palindrome

    题目 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ign ...

  7. 学习Gulp过程中遇到的一些单词含义

    注:以下有的单词的含义不仅仅在gulp里面是一样的,在其他某些语言里面也是一样 nodejs Doc:https://nodejs.org/api/stream.html gulp Api:http: ...

  8. kali-set

    Set 简介 开源的社会工程学利用套件,通常结合metasploit(部分)来使用 更改 /etc/setoolkit下的配置文件 set_config BLEEDING_EDGE="Fal ...

  9. 九度oj 题目1340:小A的计算器

    题目描述: 以往的操作系统内部的数据表示都是二进制方式,小A新写了一个操作系统,系统内部的数据表示为26进制,其中0-25分别由a-z表示. 现在小A要在这个操作系统上实现一个计算器,这个计算器要能实 ...

  10. P1279 字串距离 (动态规划)

    题目描述 设有字符串X,我们称在X的头尾及中间插入任意多个空格后构成的新字符串为X的扩展串,如字符串X为”abcbcd”,则字符串“abcb□cd”,“□a□bcbcd□”和“abcb□cd□”都是X ...