Spring Boot 3.1升级至3.2导致Azure Kubernetes JDBC配置失效
Spring Boot 3.x升级至3.2+/3.3.0时Azure无密码JDBC认证错误问题
将Spring Boot从3.1.x版本(测试过3.1.4及3.1.10)升级到3.2.x版本(尝试过3.2.0和3.2.5),或升级到3.3.0时,部署到Azure Kubernetes集群会触发错误:
The server requested password-based authentication, but no password was provided by plugin null
本地数据库运行无异常,推测该问题与Spring Cloud Azure的无密码令牌式JDBC认证相关。
正常运行的数据库配置(Spring Boot 3.1.x + Spring Cloud Azure)
该配置通过Spring Cloud Azure无密码方式连接数据库,使用映射到Postgres组角色的运行时ID:
spring: datasource: driver-class-name: org.postgresql.Driver url: jdbc:postgresql://our-namespace-01.postgres.database.azure.com:5432/my-database?currentSchema=my-db-schema username: our-postgres-runtime-id azure: passwordless-enabled: true credential: managed-identity-enabled: true client-id: ${cf.runtime.clientid} # 由Kubernetes的kconf替换
3.1.x版本的依赖配置片段
以下是build.gradle的相关配置片段:
plugins { id 'io.spring.dependency-management' version '1.1.4' id 'jacoco' id 'java' id 'maven-publish' id 'org.springframework.boot' version '3.2.5' } java { toolchain { languageVersion = JavaLanguageVersion.of(17) } } apply plugin: 'application' configurations { implementation.exclude group: "org.springframework.boot", module: "spring-boot-starter-logging" implementation.exclude group: 'ch.qos.logback', module: 'logback-classic' } // 其余依赖内容省略...
升级至Spring Boot 3.3.0的依赖配置
完整build.gradle配置如下:
import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.api.tasks.testing.logging.TestLogEvent plugins { id 'io.spring.dependency-management' version '1.1.5' id 'jacoco' id 'java' id 'org.springframework.boot' version '3.3.0' } java { toolchain { languageVersion = JavaLanguageVersion.of(17) } } apply plugin: 'application' // 其余配置内容省略...
测试时的Bean处理警告
运行测试时出现以下警告,请问该警告是否与上述认证错误相关?
11.06.2024 00:57:05,882 [CID:] [Test worker] WARN [egate$BeanPostProcessorChecker] - Bean 'jdbcConnectionDetails' of type [org.springframework.boot.autoconfigure.jdbc.PropertiesJdbcConnectionDetails] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected into a currently created BeanPostProcessor [jobRegistryBeanPostProcessor]? Check the corresponding BeanPostProcessor declaration and its dependencies. // 其余警告内容省略...
内容的提问来源于stack exchange,提问作者oligofren
相关产品推荐
相关产品推荐

