feat: spring-cloud-starter-bootstrap is no longer supported#4260
feat: spring-cloud-starter-bootstrap is no longer supported#4260xuxiaowei-com-cn wants to merge 7 commits intoalibaba:2025.1.xfrom
Conversation
When `org.springframework.cloud:spring-cloud-starter-bootstrap` is present in the classpath, the application will fail to start with a descriptive error message. This is to enforce the new configuration loading mechanism and avoid conflicts. Reference: alibaba#4259
|
Honestly, throwing an exception to directly block the application startup might not be the best approach here. It feels a bit too aggressive. In many users' projects, dependency trees can be quite messy (often unintentionally😥) Instead, we could print an ERROR log during the initialization phase or when components are loading. We can warn the user that spring-cloud-starter-bootstrap has been detected, which implies that nacos config might not work as expected. |
- Add `spring.cloud.nacos.config.enable-check-bootstrap` property (default true) to allow users to disable the bootstrap check. - Rename `checkBootstrapConfiguration` bean to `checkBootstrap` and add conditional property check.
…f throwing exception
|
The exception has been modified to a warning log. |
…oudAutoConfiguration
| /** | ||
| * whether to check if the bootstrap configuration is enabled, default is true. | ||
| */ | ||
| private boolean enableCheckBootstrap = true; |
There was a problem hiding this comment.
虽然该属性没有实际使用到,但是有利于使用者发现此功能,比如:代码自动提示、yaml 代码不会出现警告等等
There was a problem hiding this comment.
这个功能默认开,应该无需开发者额外关注和特意去关闭,理论上确实用不到的哈,我的建议还是删除~
| @ConditionalOnProperty(name = "spring.cloud.nacos.config.enable-check-bootstrap", matchIfMissing = true) | ||
| @ConditionalOnClass(name = "org.springframework.cloud.bootstrap.marker.Marker") | ||
| public Object checkBootstrapConfiguration() { | ||
| log.warn("Including 'org.springframework.cloud:spring-cloud-starter-bootstrap' is prohibited. " |
There was a problem hiding this comment.
如果考虑 warn 级别日志更合适的话,这里不建议说是 【prohibited】,改为 【not work properly】可能好一些
| public Object checkBootstrapConfiguration() { | ||
| log.warn("Including 'org.springframework.cloud:spring-cloud-starter-bootstrap' is prohibited. " | ||
| + "For details, please refer to: https://github.com/alibaba/spring-cloud-alibaba/issues/4259"); | ||
| return null; |
There was a problem hiding this comment.
return null 看起来怪怪的,也许你觉得这个不重要,因为主要想使用@ConditionalOnClass(name = "org.springframework.cloud.bootstrap.marker.Marker") 这个扩展点来打印一条日志。但是 @Bean 注解里面 return null 还是不太妥当,这是一种反模式。可能得换一种方式来实现这个日志打印。AI 工具给的建议是直接使用内部配置类,这确实也挺简单的,你可以看一下哈:
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(name = "spring.cloud.nacos.config.enable-check-bootstrap", matchIfMissing = true)
@ConditionalOnClass(name = "org.springframework.cloud.bootstrap.marker.Marker")
static class BootstrapDetectionConfiguration {
BootstrapDetectionConfiguration() {
LoggerFactory.getLogger(BootstrapDetectionConfiguration.class)
.warn("Detected 'spring-cloud-starter-bootstrap' on the classpath...");
}
}|
已处理 |
| static class BootstrapDetectionConfiguration { | ||
| BootstrapDetectionConfiguration() { | ||
| LoggerFactory.getLogger(BootstrapDetectionConfiguration.class) | ||
| .warn("Including 'org.springframework.cloud:spring-cloud-starter-bootstrap' not work properly. " |
There was a problem hiding this comment.
这里感觉语法有问题,可以考虑改为:Including 'org.springframework.cloud:spring-cloud-starter-bootstrap' will prevent Nacos Config from working properly. Please remove this dependency. For details...

When
org.springframework.cloud:spring-cloud-starter-bootstrapis present in the classpath, the application will fail to start with a descriptive error message. This is to enforce the new configuration loading mechanism and avoid conflicts.Reference: #4259
Describe what this PR does / why we need it
Does this pull request fix one issue?
Describe how you did it
Describe how to verify it
Special notes for reviews