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

升级Spring Boot 2后bootstrap.properties占位符解析及启动报错咨询

Fixing Bootstrap.properties Issues in Spring Boot 2 + Spring Cloud

Hey there, I’ve run into these exact issues before when upgrading and combining Spring Boot 2 with Spring Cloud—let’s work through them step by step:

1. Placeholder Parsing Failures in bootstrap.properties After Spring Boot 2 Upgrade

This usually boils down to a key change in how Spring Boot 2.x handles the bootstrap context, especially if you’re using newer Spring Cloud versions.

Why it happens:

Starting with Spring Cloud 2020.0.0 (codename Ilford), the bootstrap context (which loads bootstrap.properties/bootstrap.yml) is disabled by default. In older versions, this context was automatically enabled to pull configuration from sources like Config Server, but now you need to explicitly turn it on.

Fixes:

  • Add the bootstrap starter dependency:
    For Maven projects, drop this into your pom.xml:
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bootstrap</artifactId>
    </dependency>
    
    For Gradle projects, add this line to your build.gradle:
    implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap'
    
  • Double-check placeholder syntax:
    Make sure your placeholders use the standard ${} format (e.g., ${spring.application.name}) and that the referenced properties exist either in local config or your remote config source. If you rely on custom placeholder syntax, you’ll need to configure a PropertyPlaceholderConfigurer bean explicitly.

This is almost always caused by version mismatches or missing required dependencies.

Why it happens:

  • Version incompatibility: Spring Boot and Spring Cloud have strict version compatibility rules. Using mismatched versions (like Spring Boot 2.7 with Spring Cloud 2020.0.x) will break context initialization and throw errors related to bootstrap loading.
  • Missing bootstrap starter: As mentioned earlier, newer Spring Cloud versions don’t include bootstrap support out of the box. Without the starter, the app can’t process bootstrap.properties at all.
  • Invalid config syntax: A typo, unclosed placeholder, or malformed property in bootstrap.properties will crash the startup process.

Fixes:

  • Align Spring Boot and Spring Cloud versions:
    Stick to the official compatibility pairs. For example:
    • Spring Boot 2.7.x ↔ Spring Cloud 2021.0.x (Jubilee)
    • Spring Boot 3.x ↔ Spring Cloud 2022.0.x (Kilburn)
  • Add the spring-cloud-starter-bootstrap dependency:
    Same as the fix for issue 1—this re-enables the bootstrap context to load your config file.
  • Validate your bootstrap.properties:
    Scan for typos, unclosed ${} placeholders, or invalid property names. For example, avoid empty values like spring.cloud.config.uri= or misspelled keys like spring.applicaiton.name.
  • Confirm config file location:
    Make sure bootstrap.properties lives in the standard src/main/resources directory. If you’re using a custom path, specify it with the spring.config.location system property or environment variable.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 08:09:54