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

Spring Boot 3.5.0升级后DataSourceProperties Bean无法找到问题咨询及变更原因排查

Spring Boot 3.5.0升级后DataSourceProperties Bean无法找到问题咨询及变更原因排查

Hey there! Let's dig into why you're hitting this issue after upgrading to Spring Boot 3.5.0, and what changed under the hood.

First, let's recap your setup to make sure we're on the same page:

  • You excluded DataSourceAutoConfiguration to customize your datasource setup (specifically to use LazyConnectionDataSourceProxy)
  • In Spring Boot 3.4.6, your custom DatabaseConfiguration could inject DataSourceProperties without any extra steps
  • After upgrading to 3.5.0, you got the "required a bean of type 'DataSourceProperties' that could not be found" error, which you fixed by adding @EnableConfigurationProperties(DataSourceProperties.class) to your application class

What Changed in Spring Boot 3.5.0?

The core issue is a deliberate change in how Spring Boot handles DataSourceProperties when you exclude DataSourceAutoConfiguration:

  • In Spring Boot 3.4.x and earlier, even if you excluded DataSourceAutoConfiguration, DataSourceProperties was still automatically registered as a bean. This happened because the auto-config system implicitly ensured this core properties class was available, even when the full datasource auto-config was turned off.
  • In Spring Boot 3.5.0, the team adjusted this logic to be more strict. Now, if you exclude DataSourceAutoConfiguration, DataSourceProperties is no longer automatically registered. This aligns with the principle of "opt-in" configuration—if you're opting out of the default datasource auto-config, Spring Boot no longer assumes you want the default properties bean either.

Why Your Fix Works

Adding @EnableConfigurationProperties(DataSourceProperties.class) explicitly tells Spring Boot to register the DataSourceProperties bean, binding it to your spring.datasource.* properties in application.properties/application.yml. This is the intended way to bring back the properties bean when you've excluded the auto-config that would normally register it.

Alternative Fix (If You Prefer)

If you'd rather not use @EnableConfigurationProperties at the application level, you can also define the DataSourceProperties bean directly in your DatabaseConfiguration:

@Bean
@ConfigurationProperties(prefix = "spring.datasource")
public DataSourceProperties dataSourceProperties() {
    return new DataSourceProperties();
}

This achieves the same result—providing the required bean for your hikariDataSource method to use.

Wrap-Up

This change was made to give developers more control over their configuration when opting out of auto-config. It's a small breaking change, but it makes the auto-config behavior more predictable: if you turn off the default datasource setup, you have to explicitly opt into the properties bean if you need it.

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.08 08:54:30