HikariPool-1 - jdbcUrl is required with driverClassName
Asked Answered
V

3

29

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

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.

Vernievernier answered 18/3, 2018 at 21:5 Comment(5)
Shouldn't your url look something like jdbc:postgresql://host:5432/dbDonitadonjon
No. jdbc.postgresql.org/documentation/80/connect.html In addition, it worked before the Spring Boot version changed.Vernievernier
OK. One possibility is that the the config variables aren't being picked.Donitadonjon
This is not the current version of the program, but very similar github.com/JonkiPro/REST-Web-Services/blob/master/web/src/main/…. I only have this configuration for the database. Can I somehow configure these Hikari? I never heard about it.Vernievernier
Just drop the driver-class-name property. Spring Boot will determine the driver class from the URL alone.Ethelinda
S
33

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

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 is the default pool in spring boot 2.

so you can replace the config 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
@Primary
@ConfigurationProperties("app.datasource")
public DataSourceProperties dataSourceProperties() {
    return new DataSourceProperties();
}

@Bean
@ConfigurationProperties("app.datasource")
public DataSource dataSource(DataSourceProperties properties) {
    return properties.initializeDataSourceBuilder().
        .build();
}
Slipnoose answered 16/4, 2018 at 10:14 Comment(2)
Solved the issue for me, i have 2 datasource and in my properties i just replaced like app.datasource1.url to app.datasource1.jdbc-urlKlong
Also you may have a look here to see a different approach creating the datasource: baeldung.com/hikaricp#1-creating-a-datasourcePhysicalism
N
30

Either remove spring.datasource.driver-class-name property or rename the spring.datasource.url property to spring.datasource.jdbc-url.

This is reported in your error:

java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName

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

Nether answered 16/4, 2018 at 12:59 Comment(0)
C
2

I've also faced the same issue while configuring two database and below solution resolved my issue. Solution: rename the spring.datasource.url property to spring.datasource.jdbc-url

Caesarism answered 9/7, 2023 at 7:51 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Gremlin

© 2022 - 2024 — McMap. All rights reserved.