Fix BeanPostProcessorChecker warnings with Spring Cloud 2025.0.0#754
Fix BeanPostProcessorChecker warnings with Spring Cloud 2025.0.0#754
Conversation
Replace static DynamicDataSourceProperties bean method with @EnableConfigurationProperties annotation to properly integrate with Spring Cloud's configurationPropertiesBeans BeanPostProcessor. Co-authored-by: huayanYu <16700837+huayanYu@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes BeanPostProcessorChecker warnings that occur when using Spring Cloud 2025.0.0 with the dynamic-datasource library. The warnings were caused by the static bean method for DynamicDataSourceProperties triggering early instantiation before Spring Cloud's configurationPropertiesBeans BeanPostProcessor was fully initialized.
Key Changes
- Replaced static
dynamicDataSourceProperties()bean method with@EnableConfigurationProperties(DynamicDataSourceProperties.class)annotation - Applied consistently across all three Spring Boot starter modules
- Maintains the same functionality while resolving the bean initialization order issue
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| dynamic-datasource-spring-boot-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAopConfiguration.java | Adds @EnableConfigurationProperties annotation and removes static bean method for Spring Boot 2.x starter |
| dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAopConfiguration.java | Adds @EnableConfigurationProperties annotation and removes static bean method for Spring Boot 3.x starter |
| dynamic-datasource-spring-boot4-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAopConfiguration.java | Adds @EnableConfigurationProperties annotation and removes static bean method for Spring Boot 4.x starter |
The changes look good overall. The approach is correct and follows Spring Boot best practices for registering @ConfigurationProperties beans. The fix properly addresses the root cause of the BeanPostProcessorChecker warnings by ensuring that DynamicDataSourceProperties is registered through the standard @EnableConfigurationProperties mechanism rather than through a static bean method that causes early initialization.
The implementation is consistent across all three starter modules, and the constructor injection pattern in DynamicDataSourceAopConfiguration will work seamlessly with the new annotation-based registration.
When using Spring Cloud 2025.0.0, startup produces four
BeanPostProcessorCheckerwarnings about beans not eligible for processing by all BeanPostProcessors. This occurs becauseDynamicDataSourcePropertiesis registered via a static bean method, which triggers early instantiation before Spring Cloud'sconfigurationPropertiesBeansBeanPostProcessor is fully initialized.Changes
dynamicDataSourceProperties()bean method with@EnableConfigurationProperties(DynamicDataSourceProperties.class)annotationdynamic-datasource-spring-boot-starterdynamic-datasource-spring-boot3-starterdynamic-datasource-spring-boot4-starterBefore
After
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
maven.aliyun.com/usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant(dns block)/usr/lib/jvm/temurin-8-jdk-amd64/bin/java /usr/lib/jvm/temurin-8-jdk-amd64/bin/java -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.13-bin/5xuhj0ry160q40clulazy9h7d/gradle-8.13/lib/gradle-daemon-main-8.13.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.13-bin/5xuhj0ry160q40clulazy9h7d/gradle-8.13/lib/agents/gradle-instrumentation-agent-8.13.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.13(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>使用Spring cloud 2025.0.0,启动会报四个BeanPostProcessorChecker的警告</issue_title>
<issue_description>```
2025-07-21T18:46:41.413+08:00 WARN 12804 --- [test] [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.commons.config.CommonsConfigAutoConfiguration' of type [org.springframework.cloud.commons.config.CommonsConfigAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected/applied to a currently created BeanPostProcessor [configurationPropertiesBeans]? Check the corresponding BeanPostProcessor declaration and its dependencies/advisors. If this bean does not have to be post-processed, declare it with ROLE_INFRASTRUCTURE.
2025-07-21T18:46:41.413+08:00 WARN 12804 --- [test] [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.client.loadbalancer.LoadBalancerDefaultMappingsProviderAutoConfiguration' of type [org.springframework.cloud.client.loadbalancer.LoadBalancerDefaultMappingsProviderAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected/applied to a currently created BeanPostProcessor [configurationPropertiesBeans]? Check the corresponding BeanPostProcessor declaration and its dependencies/advisors. If this bean does not have to be post-processed, declare it with ROLE_INFRASTRUCTURE.
2025-07-21T18:46:41.415+08:00 WARN 12804 --- [test] [ main] trationDelegate$BeanPostProcessorChecker : Bean 'loadBalancerClientsDefaultsMappingsProvider' of type [org.springframework.cloud.client.loadbalancer.LoadBalancerDefaultMappingsProviderAutoConfiguration$$Lambda/0x000001dd2049a888] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected/applied to a currently created BeanPostProcessor [configurationPropertiesBeans]? Check the corresponding BeanPostProcessor declaration and its dependencies/advisors. If this bean does not have to be post-processed, declare it with ROLE_INFRASTRUCTURE.
2025-07-21T18:46:41.415+08:00 WARN 12804 --- [test] [ main] trationDelegate$BeanPostProcessorChecker : Bean 'defaultsBindHandlerAdvisor' of type [org.springframework.cloud.commons.config.DefaultsBindHandlerAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected/applied to a currently created BeanPostProcessor [configurationPropertiesBeans]? Check the corresponding BeanPostProcessor declaration and its dependencies/advisors. If this bean does not have to be post-processed, declare it with ROLE_INFRASTRUCTURE.
4.0.0
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.