Java HikariPool-1 - 驱动程序类名称需要 jdbcUrl

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49352800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 03:00:17  来源:igfitidea点击:

HikariPool-1 - jdbcUrl is required with driverClassName

javaspringspring-mvcspring-booteclipselink

提问by rytyrtytr

I went back to programming my old program https://github.com/JonkiPro/REST-Web-Services. I've updated Spring Boot from version 15.6 to version 2.0.0. I have encountered many problems with compilation, but I can not deal with one. Well, during compilation, he throws me in the console

我回去编写我的旧程序https://github.com/JonkiPro/REST-Web-Services。我已经将 Spring Boot 从 15.6 版更新到了 2.0.0 版。我在编译方面遇到过很多问题,但我无法处理一个。嗯,在编译过程中,他把我扔进了控制台

2018-03-18 21:54:53.339 ERROR 3220 --- [ost-startStop-1] com.zaxxer.hikari.HikariConfig           : HikariPool-1 - jdbcUrl is required with driverClassName.
2018-03-18 21:54:55.392  INFO 3220 --- [ost-startStop-1] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'unit'
2018-03-18 21:54:56.698  INFO 3220 --- [ost-startStop-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'unit'
2018-03-18 21:54:56.778 ERROR 3220 --- [ost-startStop-1] com.zaxxer.hikari.HikariConfig           : HikariPool-1 - jdbcUrl is required with driverClassName.
2018-03-18 21:54:56.782 ERROR 3220 --- [ost-startStop-1] o.s.b.web.embedded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'webSecurityConfig': Unsatisfied dependency expressed through field 'userDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsService' defined in file [C:\Users\Jonatan\Documents\GitHub\REST-Web-Services\web\out\production\classes\com\web\web\security\service\impl\UserDetailsServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Cannot create inner bean '(inner bean)#65d6e77b' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#65d6e77b': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': Post-processing of FactoryBean's singleton object failed; nested exception is java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName.
2018-03-18 21:54:56.821  WARN 3220 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat

I've never had such a mistake. I do not know what it means completely. My properties for the base look like this

我从来没有犯过这样的错误。我完全不知道这意味着什么。我的基地属性看起来像这样

spring:
  datasource:
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql:database
    username: root
    password: root
    schema: classpath:/db/init/schema.sql

I do not know how to deal with this error. I've been programming quite a long time, but for the first time I'm meeting the concept of hikari. I'm using a Tomcat(in Spring Boot) server and a PostgreSQL database.

我不知道如何处理这个错误。我已经编程了很长时间,但这是我第一次遇到hikari. 我正在使用 Tomcat(在 Spring Boot 中)服务器和 PostgreSQL 数据库。

回答by Maurizio Lo Bosco

I had the same issue in another context. From the 79. Data Access - Configure a Custom DataSource

我在另一个上下文中遇到了同样的问题。来自79. 数据访问 - 配置自定义数据源

if you happen to have Hikari on the classpath, this basic setup does not work, because Hikari has no url property (but does have a jdbcUrl property)

如果你碰巧在类路径上有 Hikari,这个基本设置不起作用,因为 Hikari 没有 url 属性(但有 jdbcUrl 属性)

Hikari is the default pool in spring boot 2.

Hikari 是 spring boot 2 中的默认池。

so you can replace the config url: jdbc:postgresql:database-> jdbc-url: jdbc:postgresql:database

所以你可以替换配置 url: jdbc:postgresql:database- >jdbc-url: jdbc:postgresql:database

or you can keep the config but you need to define another Bean to handle the mapping (aliases)

或者您可以保留配置但您需要定义另一个 Bean 来处理映射(别名)

@Bean
@Primary
@ConfigurationProperties("app.datasource")
public DataSourceProperties dataSourceProperties() {
    return new DataSourceProperties();
}

@Bean
@ConfigurationProperties("app.datasource")
public DataSource dataSource(DataSourceProperties properties) {
    return properties.initializeDataSourceBuilder().
        .build();
}

回答by Karol Dowbecki

Either remove spring.datasource.driver-class-nameproperty or rename the spring.datasource.urlproperty to spring.datasource.jdbc-url.

删除spring.datasource.driver-class-name属性或将spring.datasource.url属性重命名为spring.datasource.jdbc-url.

This is reported in your error:

这是在您的错误中报告的:

java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName

java.lang.IllegalArgumentException:驱动程序类名称需要 jdbcUrl

First option looks cleaner and Spring Boot will figure out the default driver class name based on the spring.datasource.urlproperty value (see org.springframework.boot.jdbc.DatabaseDriverclass if you want to debug this).

第一个选项看起来更清晰,Spring Boot 将根据spring.datasource.url属性值找出默认的驱动程序类名称(org.springframework.boot.jdbc.DatabaseDriver如果要调试,请参阅类)。