【问题标题】:Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource Spring Boot无法将“”下的属性绑定到 com.zaxxer.hikari.HikariDataSource Spring Boot
【发布时间】:2018-10-17 08:41:21
【问题描述】:

当我尝试运行 Spring Boot 应用程序时出现以下错误。

Description:

Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:

    Property: driverclassname
    Value: oracle.jdbc.OracleDriver
    Origin: "driverClassName" from property source "source"
    Reason: Unable to set value for property driver-class-name

Action:

Update your application's configuration

这是same issue 我有,但我没有使用 maven。

我正在使用 spring Boot 2.0.0 和以下启动器。

dependencies {
    compile "org.springframework.boot:spring-boot-starter-web"
    compile "org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1"
    testCompile "org.springframework.boot:spring-boot-starter-test"
}

这是我的application.properties 文件

spring.datasource.url= *****
spring.datasource.username= ******
spring.datasource.password= ******

【问题讨论】:

  • 您应该描述您的配置,因为这是导致您的应用失败的原因。
  • 更新了我的问题。

标签: spring spring-boot jdbc


【解决方案1】:

我也有同样的问题(Spring boot 2),

我修正了添加驱动程序类。

查找 application.properties 文件。

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

完整代码。

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=upate
spring.datasource.url=jdbc:mysql://localhost:3306/database_name
spring.datasource.username=admin
spring.datasource.password=admin1234

【讨论】:

    【解决方案2】:

    正如Stephane Nicoll 所说,您的类路径中没有驱动程序。您需要在您的 gradle 构建中包含 jdbc 驱动程序,如下所示。但是,您不必拘泥于我提供的驱动程序版本。

    dependencies {
        compile "org.springframework.boot:spring-boot-starter-web"
        compile "org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1"
        testCompile "org.springframework.boot:spring-boot-starter-test"
        runtime('com.oracle:ojdbc7:12.1.0.2.0') 
    }
    

    【讨论】:

    • 既然你已经验证了这个问题,我只能假设这是你的问题。由于您没有像我在回答中所问的那样创建问题,因此我已经 created one myself
    • 非常感谢您指出这一点。 maven 也有同样的问题——单个 JUnit 测试没有运行,但 maven 构建运行了。解决方案是将编译范围添加到数据库连接器(在我的情况下在内存数据库中)。
    【解决方案3】:

    我在属性文件中添加了以下内容

    spring.datasource.driverclassname = com.mysql.jdbc.Driver hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

    并在 POM 文件中添加以下内容

            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
    

    现在一切正常。

    【讨论】:

    • 我正在使用 oracle 和 gradle。所以这个答案是不正确的。
    • @Bibin 在我使用 mySQL 时为我工作,但现在我遇到另一个异常:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 最后一个数据包发送成功到服务器是 0 毫秒前。驱动没有从服务器收到任何数据包。
    【解决方案4】:

    从 Spring Boot 2.0.6 更新到 Spring Boot 2.1.6 时,我遇到了同样的错误。

    application.properties 中显式设置驱动类名称spring.datasource.driver-class-name=com.mysql.jdbc.Driver 已解决问题

    【讨论】:

    • 从 Spring Boot 2.1.0 开始,mysql 连接的默认驱动程序名称是 com.mysql.cj.jdbc.Driver:github.com/spring-projects/spring-boot/issues/13688。提交:18904ec29138080dcfc707b6150dc0069b7a0ac4。如果可以使用兼容的 (driverName= com.mysql.cj.jdbc.Driver) 更新 mysql 连接器,那将是一个不错的选择。如果没有,这是一个很好的解决方法
    【解决方案5】:

    你必须添加

       <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency> 
    

    你的 pom.xml 文件中的依赖关系

    【讨论】:

      【解决方案6】:

      驱动程序不在您的类路径中,这是一个有趣的问题,我认为可以改进故障分析器以避免该误导性消息。如果这是您的问题,请确认并打开一个问题,以便我们尝试改进它。

      【讨论】:

        【解决方案7】:

        如果有人在运行 intelliJ,则此错误无法立即清除,这可能是由于缺少配置文件造成的。例如。缺少 -Dspring.profiles.active=local 的 vm args(或任何您的属性文件名)

        【讨论】:

        • 我仍然面临这个问题,尽管在运行我的应用程序时它将使用默认配置文件。所以应该没关系吧?不过似乎没有解决方案。
        • 您是否检查了您在运行配置中运行的配置文件?
        • 我没有设置任何配置文件,所以当我使用应用程序时它会说:未找到配置文件,切换到配置文件默认值。配置文件是开发人员刚刚做的正确的事情,所以我想知道为什么它会很重要。
        【解决方案8】:

        如果您正在运行 intelliJ 并遇到此问题,只需在您的 pom.xml 文件中添加此依赖项:

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        

        【讨论】:

          【解决方案9】:

          这也发生在我身上。 但是在我的 pom.xml 中添加了正确的 MySQL 版本,并将驱动程序详细信息显式添加到 application.properties 后解决了这个问题。

          1. Application.properties

            spring.datasource.driver-class-name=com.mysql.jdbc.Driver

          2. pom.xml

             <dependency>
                 <groupId>mysql</groupId>
                 <artifactId>mysql-connector-java</artifactId>
                 <version>5.1.34</version>
             </dependency>
            

          根据安装的版本将 MySQL 版本添加到 pom.xml。

          【讨论】:

            【解决方案10】:

            我们必须添加依赖并且必须删除属性“spring.datasource.driver-class-name”

             <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <scope>runtime</scope>
                </dependency> 
            

            【讨论】:

              【解决方案11】:

              你只需要在 pom.xml 中添加下面

                   <dependency>
                      <groupId>mysql</groupId>
                      <artifactId>mysql-connector-java</artifactId>
                  </dependency>
              

              【讨论】:

                【解决方案12】:

                如果你没有mysql依赖,检查你的pom.xml,可以这样添加

                <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <scope>runtime</scope>
                </dependency>
                

                更新文件之前,运行maven

                mvn clean install
                

                更新 maven 的依赖项

                【讨论】:

                  【解决方案13】:

                  我有同样的错误,错误在 pom.xml 文件中。我的 SQL 连接器依赖项有误。如果您的情况还可以,请检查 application.properties 文件,您可能不包含驱动程序

                  spring.datasource.url=jdbc:mysql://localhost:3307/test?useSSL=false
                  spring.datasource.username=root
                  spring.datasource.password=root
                  spring.jpa.show-sql=true
                  spring.jpa.generate-ddl=false
                  spring.jpa.hibernate.ddl-auto=update
                  spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
                  
                  spring.mvc.view.prefix = /WEB-INF/jsp/
                  spring.mvc.view.suffix = .jsp
                  

                  【讨论】:

                    猜你喜欢
                    • 1970-01-01
                    • 2020-11-14
                    • 1970-01-01
                    • 1970-01-01
                    • 2018-08-22
                    • 2021-11-11
                    • 2020-02-14
                    • 1970-01-01
                    • 1970-01-01
                    相关资源
                    最近更新 更多