问题分析及解决方案


问题原因: Mybatis没有找到合适的加载类,其实是大部分spring - datasource - url没有加载成功,分析原因如下所示.

  1. DataSourceAutoConfiguration会自动加载.

  2. 没有配置spring - datasource - url 属性.

  3. spring - datasource - url 配置的地址格式有问题.

  4. 配置 spring - datasource - url的文件没有加载.

方案一 (解决原因1)

排除此类的autoconfig。启动以后就可以正常运行。

@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
方案二 (解决原因2)

在application.properties/或者application.yml文件中没有添加数据库配置信息.

spring:
datasource:
url: jdbc:mysql://localhost:3306/read_data?useUnicode=true&characterEncoding=UTF-8&useSSL=false
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
方案三 (解决原因3)

在spring xml配置文件中引用了数据库地址 所以需要对:等进行转义处理.但是在application.properties/或者application.yml文件并不需要转义,错误和正确方法写在下面了.

//错误示例
spring.datasource.url = jdbc:mysql\://192.168.0.20\:1504/f_me?setUnicode=true&characterEncoding=utf8
//正确示例
spring.datasource.url = jdbc:mysql://192.168.0.20:1504/f_me?setUnicode=true&characterEncoding=utf8
方案四 (解决原因4)

yml或者properties文件没有被扫描到,需要在pom文件中<build></build>添加如下.来保证文件都能正常被扫描到并且加载成功.

<!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.yml</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.yml</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>

Mybatis配置报错:Failed to configure a DataSource: 'url' attribute is not specified and no embe...的更多相关文章

  1. SpringBoot 2.0 报错: Failed to configure a DataSource: 'url' attribute is not specified and no embe

    问题描述 *************************** APPLICATION FAILED TO START *************************** Description ...

  2. springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde

    springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde 创建 ...

  3. springboot启动报错 Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

    新建了一个springboot项目报一下错误: Failed to configure a DataSource: 'url' attribute is not specified and no em ...

  4. Spring Boot错误——SpringBoot 2.0 报错: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

    背景 使用Spring Cloud搭建微服务,服务的注册与发现(Eureka)项目启动时报错,错误如下 *************************** APPLICATION FAILED T ...

  5. Spring Boot 2.1.7 启动项目失败,报错: "Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured."

    一开始按照网上的很多解决办法是: 启动类头部声明@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}),但是这样会排除 ...

  6. springboot项目启动报错 Failed to configure a DataSource: 'url' attribute is not specified and no embedde

    参考:https://blog.csdn.net/Coyotess/article/details/80637837

  7. SpringBoot使用mybatis,发生:Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured

    最近,配置项目,使用SpringBoot2.2.1,配置mybatis访问db,配好后,使用自定义的数据源.启动发生: APPLICATION FAILED TO START ************ ...

  8. Failed to configure a DataSource: 'url' attribute is not specified and no embe...

    问题分析及解决方案 问题原因: Mybatis没有找到合适的加载类,其实是大部分spring - datasource - url没有加载成功,分析原因如下所示. DataSourceAutoConf ...

  9. springboot启动报错Failed to configure a DataSource

    2018-11-21 19:43:12.076 WARN 5392 --- [ main] ConfigServletWebServerApplicationContext : Exception e ...

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

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

随机推荐

  1. 推荐优秀国产蓝牙芯片-HS6621CxC系列

    HS6621CxC是一个优化功耗真正芯片系统(SOC)解决方案,适用于蓝牙低功耗和私有的2.4GHz应用场景.它集成了一个高性能.小功率的射频收发器,具有蓝牙基带和丰富的外围IO扩展. HS6621C ...

  2. 读后笔记 -- Python 全栈测试开发 Chapter9:Postman + Newman 实现接口自动化

    9.1 Postman 工具 9.1.4 Postman 基本操作 1. Get 请求 GET 请求的参数通过 Params 设置,最后出现在 url 地址栏上,拼接在 API 后面.  2. Pos ...

  3. 谈谈关于CDN缓存

    一.CDN是什么? 谈到CDN的作用,可以用8年买火车票的经历来形象比喻: 8年前,还没有火车票代售点一说,12306.cn更是无从说起.那时候火车票还只能在火车站的售票大厅购买,而我所住的小县城并不 ...

  4. NTP Mode 6 检测漏洞【原理扫描】

    系统: AIX7 cd /etc cp ntp.conf ntp.conf.bak vi net.conf ## 在最后加上一行 restrict default notrust nomodify n ...

  5. Maven3.6.1 (转载大佬文章)

    (30条消息) Maven3.6.1安装及配置_浅若清风过的博客-CSDN博客 1.下载https://archive.apache.org/dist/maven/maven-3/3.6.1/bina ...

  6. RSTP-快速生成树协议

    1 STP的不足之处STP协议虽然能够解决环路问题,但是由于网络拓扑收敛慢,影响了用户通信质量. 2 RSTP概述RSTP在许多方面对STP进行了优化,它的收敛速度更快,而且能够兼容STP. 通过接口 ...

  7. tp项目部署到宝塔,运行nginx时无法访问首页之外的页面

    http://www.upwqy.com/details/254.html tp项目 部署到宝塔里面 运行环境nginx 直接访问首页是可以访问的.但是请求其他的接口的时候 报404 . 需要把下面这 ...

  8. c#怎样删除指定文件名的文件

    我有一个文件夹,里面有6个文件,我现在要删除字母B开头的三个文件,只需要剩下A开头的文件即可用C#怎样操作??? foreach (string d in Directory.GetFileSyste ...

  9. Netty Reactor模型

    1.netty抽象出两个线程池:BossGroup负责监听和建立连接 :WorkerGroup 负责网络IO的读写 2.BossGroup 和 WorkerGroup 类型都是NioEventLoop ...

  10. C/C++/中宏特殊字符的含义及用法总结(“#”、“##”、"#@"、“\”等等)

    在C/C++中,宏定义是由define完成的,宏定义中有几种常见的特殊字符需要我们了解,常用的特殊字符有以下几种: #:在宏展开的时候会将#后面的参数替换成字符串: 字符串化##:将前后两个的单词拼接 ...