首页 > 数据库 >SpringBoot配置了数据库依赖 报错: Failed to configure a DataSource: 'url' attribute is not specified

SpringBoot配置了数据库依赖 报错: Failed to configure a DataSource: 'url' attribute is not specified

时间:2023-04-15 12:11:38浏览次数:48  
标签:SpringBoot no url spring yml application 报错 datasource properties

错误

2023-04-15 11:56:16.025  INFO 12028 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-04-15 11:56:16.060 ERROR 12028 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 
***************************
APPLICATION FAILED TO START
***************************
Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).


Process finished with exit code 0

 

问题描述

Spring Boot项目中含有Mybatis,打Jar包运行之后,报如下错误.

 

 

 

问题分析及解决方案

问题原因: 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.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mini_card?useUnicode=true&characterEncoding=UTF-8&servertimezone=utc&useSSL=false
spring.datasource.name=root
spring.datasource.password=root
方案三 (解决原因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>

 




 

转: https://www.jianshu.com/p/836d455663da

 

标签:SpringBoot,no,url,spring,yml,application,报错,datasource,properties
From: https://www.cnblogs.com/fps2tao/p/17320839.html

相关文章

  • Java连接RabbitMQ报错:An unexpected connection driver error occured(偶尔能连上)
    1、查看rabbitMq的状态。输入命令:rabbitmqctlstatus,发现没有报错,但是rabbit中的host是root,并不是ip地址,所以连接不上。 2、运行命令:echo【ip地址】root>>/etc/hosts。将RabbitMQ服务所在的IP地址添加到/etc/hosts中。 ......
  • ng-zorro 中nz-table 表单中nzNoResult的使用
    ng-zorrow库中的nz-table表单在无数据的情况下会默认一个无数据提示框,但是在项目中有时候需要调整这个显示框的内容,按照官放文档说明没有达到预期效果,研究了下最终发现了两种实现方式,一种是官方说明的方式代码如下采用模板的方式改写默认的样式<nz-table[nzData]="listO......
  • Springboot-2
    1.springboot自动装配原理1.1springboot包扫描原理包建议放在主类所在包或者子包。默认包扫描的是主类所在的包以及子包。主函数运行时会加载使用@SpringBootApplication标记的类,-->包含@SpringBootApplication-->@EnableAutoConfiguration-->@AutoConfigurationPackage--......
  • 怎么用Jupyter Notebook对数据集进行清洗和标注
    数据清洗是数据预处理的一部分,是数据分析和建模前必须进行的重要步骤。数据清洗可以帮助我们解决数据中包含的噪声、异常值、缺失值、重复数据等问题,从而提高数据的质量和可靠性。如果不进行数据清洗,可能会影响后续的数据分析和建模结果,甚至产生误导性的结论。因此,在进行任何数据......
  • TypeScript 报错:Type '({ filename: string; createTime: string; filePath: string;
    问题:因为TypeScript不支持直接给一个接口类型的变量赋一个未知的值。如consta:A={ name:'s'};你需要给这样的对象或数组值使用as指定一个类型。正确写法:consta:A={ name:'s'}asA;数组写法一样:consta:A[]=[ { name:'s' }]asA[];使用as将一......
  • springboot连接不同数据库的写法
    MySQL当url连接不指定/数据库名可以访问到mysql服务器上有权限的任何库,但是所有sql需要加上库名前缀.pom<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency>配置spring:datasource:driver-class-n......
  • 0007容器之unordered_multiset
    #include<list>#include<iostream>#include<ve......
  • 0008容器之unordered_multimap
    #include<list>#include<iostream>#include<vector>#include<stdexcept>#include<string>#include<cstdlib>//abort()#include<cstdio>//snprintf();整数转字符#include<ctime>#include<algorithm>#include<ar......
  • 2023-04-14 Fatal error: Call to a member function fetch_assoc() on a non-object
    问题:php报错。业务场景:使用update语句去更新数据库字段。原因:update接收值不正确。原代码:$query="UPDATEstudentSETdate=now()WHEREid=$id";$result=$mysqli->query($query2)ordie($mysqli->error);//问题出在这$data=$result->fetch_assoc(); i......
  • SpringBoot 集成 MybatisPlus 九——逻辑删除
    1逻辑删除的概念逻辑删除不会在数据库中删除数据,只是通过一个字段用来标识被删除的记录,数据仍然保存在数据库中。在实际的工作当中,因为数据非常重要,为了防止因用户误操作删除数据后无法恢复的问题,我们通常不会对数据做物理删除,即将数据从数据库中直接删除。而是多采用逻辑删除的方......