You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 3.4.0连接PostgreSQL出现数据源信息异常但项目正常运行

问题描述

我正在使用Spring Boot 3.4.0(Snapshot)、Maven、Java 22,搭配PostgreSQL数据库。以下是我的application.properties配置:

spring.application.name=api
spring.datasource.url = jdbc:postgresql://localhost:5432/my_database?verifyServerCertificate=false&useSSL=false&requireSSL=false
spring.datasource.username = root
spring.datasource.password = password
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=validate

运行项目时,看到如下日志信息(并非异常,只是信息展示异常):

Database JDBC URL [Connecting through datasourcenull]
Database driver: undefined/unknown
Database version: 16.4
Autocommit mode: undefined/unknown
Isolation level: undefined/unknown
Minimum pool size: undefined/unknown
Maximum pool size: undefined/unknown

但项目其余功能均正常运行,完整启动日志如下:

Scanning for projects...

---------------------------< com.stiven:api >---------------------------
Building api 0.0.1-SNAPSHOT
  from pom.xml
--------------------------------[ jar ]---------------------------------

--- resources:3.3.1:resources (default-resources) @ api ---
Copying 1 resource from src/main/resources to target/classes
Copying 0 resource from src/main/resources to target/classes

--- compiler:3.13.0:compile (default-compile) @ api ---
Nothing to compile - all classes are up to date.

--- exec:3.1.0:exec (default-cli) @ api ---

  .   ____          _            __ _ _
 /\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::       (v3.4.0-SNAPSHOT)

2024-09-07T22:14:37.723-04:00  INFO 117983 --- [api] [           main] com.stiven.api.ApiApplication            : Starting ApiApplication using Java 22.0.1 with PID 117983 (/home/stiven-guillermo-bueno-reynoso/Documents/FarmacyAPI/target/classes started by stiven-guillermo-bueno-reynoso in /home/stiven-guillermo-bueno-reynoso/Documents/FarmacyAPI)
2024-09-07T22:14:37.736-04:00  INFO 117983 --- [api] [           main] com.stiven.api.ApiApplication            : No active profile set, falling back to 1 default profile: "default"
2024-09-07T22:14:39.355-04:00  INFO 117983 --- [api] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2024-09-07T22:14:39.495-04:00  INFO 117983 --- [api] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 120 ms. Found 1 JPA repository interface.
2024-09-07T22:14:40.524-04:00  INFO 117983 --- [api] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8080 (http)
2024-09-07T22:14:40.556-04:00  INFO 117983 --- [api] [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2024-09-07T22:14:40.557-04:00  INFO 117983 --- [api] [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.28]
2024-09-07T22:14:40.662-04:00  INFO 117983 --- [api] [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2024-09-07T22:14:40.664-04:00  INFO 117983 --- [api] [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2816 ms
2024-09-07T22:14:40.960-04:00  INFO 117983 --- [api] [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2024-09-07T22:14:41.040-04:00  INFO 117983 --- [api] [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 6.6.0.Final
2024-09-07T22:14:41.099-04:00  INFO 117983 --- [api] [           main] o.h.c.internal.RegionFactoryInitiator    : HHH000026: Second-level cache disabled
2024-09-07T22:14:41.739-04:00  INFO 117983 --- [api] [           main] o.s.o.j.p.SpringPersistenceUnitInfo      : No LoadTimeWeaver setup: ignoring JPA class transformer
2024-09-07T22:14:41.791-04:00  INFO 117983 --- [api] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2024-09-07T22:14:42.504-04:00  INFO 117983 --- [api] [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection org.postgresql.jdbc.PgConnection@5cdf221a
2024-09-07T22:14:42.507-04:00  INFO 117983 --- [api] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2024-09-07T22:14:42.546-04:00  WARN 117983 --- [api] [           main] org.hibernate.orm.deprecation            : HHH90000025: PostgreSQLDialect does not need to be specified explicitly using 'hibernate.dialect' (remove the property setting and it will be selected by default)
2024-09-07T22:14:42.573-04:00  INFO 117983 --- [api] [           main] org.hibernate.orm.connections.pooling    : HHH10001005: Database info:
    Database JDBC URL [Connecting through datasourcenull]
    Database driver: undefined/unknown
    Database version: 16.4
    Autocommit mode: undefined/unknown
    Isolation level: undefined/unknown
    Minimum pool size: undefined/unknown
    Maximum pool size: undefined/unknown
2024-09-07T22:14:44.689-04:00  INFO 117983 --- [api] [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
2024-09-07T22:14:44.802-04:00  INFO 117983 --- [api] [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2024-09-07T22:14:45.223-04:00  INFO 117983 --- [api] [           main] o.s.d.j.r.query.QueryEnhancerFactory     : Hibernate is in classpath; If applicable, HQL parser will be used.
2024-09-07T22:14:45.324-04:00  WARN 117983 --- [api] [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2024-09-07T22:14:46.025-04:00  INFO 117983 --- [api] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port 8080 (http) with context path '/'
2024-09-07T22:14:46.046-04:00  INFO 117983 --- [api] [           main] com.stiven.api.ApiApplication            : Started ApiApplication in 9.314 seconds (process running for 9.87)

我尝试修改了application.properties中的spring.jpa.hibernate.ddl-auto、spring.jpa.database-platform以及spring.datasource.driver-class-name配置,但问题依旧。请问这是什么原因导致的?

原因分析与解决办法

首先明确:这条日志不是异常,只是Hibernate日志输出逻辑的小问题,完全不影响数据库连接和项目功能——从启动日志能看到Hikari连接池已经成功初始化并获取了PostgreSQL连接,项目也正常启动了。

具体原因:

  1. 你使用的Hibernate 6.6.0.Final(Spring Boot 3.4.0-SNAPSHOT默认依赖版本)在通过Spring提供的Hikari数据源获取连接时,日志模块无法正确从数据源中提取URL、驱动、连接池参数等信息,导致输出undefined/unknown这类占位内容。
  2. 日志里的Connecting through datasourcenull是字符串拼接错误,实际数据源是正常的,只是日志输出时没正确填充数据源名称。

解决建议:

  • 如果你只是在意日志美观,完全不用修改,项目功能不受影响,这只是日志展示的小bug。
  • 可以等待Spring Boot 3.4.0正式版,或者手动升级Hibernate到后续修复版本,官方大概率会解决这个日志输出问题。
  • 同时按照日志提示,去掉spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect配置,Hibernate 6+会自动识别PostgreSQL方言,手动配置反而会触发废弃警告。

内容的提问来源于stack exchange,提问作者user27249990

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 15:34:49