zoukankan      html  css  js  c++  java
  • 关于“Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.”

    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).

    错误原因:

    显然,根据错误原因可知找不到数据源配置。但是由于依赖方提供的API依赖中引用了一些多余的依赖触发了该自动化配置的加载,详情查看:https://blog.csdn.net/dyc87112/article/details/73739535,导致数据源配置自动启动生效。

    这里是由于依赖了:

    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>2.1.1</version>
    </dependency>

    解决方案:

    1.不配置数据源的情况下:

    @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, MailSenderAutoConfiguration.class})

    详细请参考:https://zhuanlan.zhihu.com/p/96508798

    2.配置数据源:本文数据源配置在yml文件中:

    spring:
      datasource:
        url: jdbc:mysql://xxxxxxxxxx
        username: xxx
        password: xxx
        driver-class-name: com.mysql.jdbc.Driver

    注意:pom文件中package类型不能为pom,否则项目编译后target中没有yml配置文件,同理打包后jar包中也没有yml配置文件。

    如下位置:

     <groupId>com.xxx</groupId>
     <artifactId>demo</artifactId>
     <version>0.0.1-SNAPSHOT</version>
     <name>demo</name>
    <!--<package>pom</package>--> <description>Demo project for Spring Boot</description>

    以上!

    
    
  • 相关阅读:
    getRandomInt getRandomString
    git 换行符替换
    Versions maven plugin 修改版本
    spotless-maven-plugin java代码自动格式化mvn spotless:apply -fn
    eclipse.ini
    JVM架构和GC垃圾回收机制
    查看搜狗浏览器记住的密码
    TestGc finalize()
    Storm个人学习总结
    mongo嵌套查询
  • 原文地址:https://www.cnblogs.com/jixiegongdi/p/13452177.html
Copyright © 2011-2022 走看看