Spring MVC HikariPool-1 -driverClassName需要jdbcUrl

brjng4g3  于 2023-08-06  发布在  Spring
关注(0)|答案(3)|浏览(226)

我回到我的旧程序https://github.com/JonkiPro/REST-Web-Services编程。我已经将Sping 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

字符串
我从没犯过这样的错误。我完全不知道这是什么意思。我的基地属性看起来像这样

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


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

smdnsysy

smdnsysy1#

我在另一个背景下遇到了同样的问题。从79。数据访问-配置自定义数据源
如果您碰巧在类路径上有Hikari,这个基本的设置就不起作用了,因为Hikari没有url属性(但是有jdbcUrl属性)
Hikari是Sping Boot 2中的默认池。
所以你可以替换配置url: jdbc:postgresql:database-> jdbc-url: jdbc:postgresql:database
或者您可以保留配置,但需要定义另一个Bean来处理Map(别名)

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

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

字符串

m1m5dgzv

m1m5dgzv2#

删除spring.datasource.driver-class-name属性或将spring.datasource.url属性重命名为spring.datasource.jdbc-url
这在您的错误中报告:
异常错误:driverClassName需要jdbcUrl
第一个选项看起来更干净,Sping Boot 将根据spring.datasource.url属性值计算出默认的驱动程序类名(如果你想调试这个,请参阅org.springframework.boot.jdbc.DatabaseDriver class)。

6psbrbz9

6psbrbz93#

我在配置两个数据库时也遇到了同样的问题,下面的解决方案解决了我的问题。解决方案:将spring.datasource.url属性重命名为spring.datasource.jdbc-url

相关问题