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

Spring Boot API启动失败,配置属性名carWasher不符合命名规范报错

错误根因

Spring Boot 2.2及以上版本默认开启配置属性命名校验,要求配置属性的标准命名必须是kebab-case(短横线分隔小写命名),仅允许包含小写字母、数字、短横线,且必须以字母开头。你当前使用的驼峰命名carWasher包含大写字母W,不符合规范导致启动失败。

具体修改方案

1. 调整配置类注解前缀

找到报错提示的配置类com.carWasher.properties.CarWasherProperties,修改类上的@ConfigurationProperties注解的prefix值:

// 修改前
@ConfigurationProperties(prefix = "carWasher")
public class CarWasherProperties {
  // 类原有内容
}

// 修改后
@ConfigurationProperties(prefix = "car-washer")
public class CarWasherProperties {
  // 类原有内容
}

2. 调整配置文件中的对应配置项

所有carWasher开头的配置项统一改为car-washer开头:

  • 若使用application.properties格式:
# 修改前
carWasher.enable=true
carWasher.max-task=5

# 修改后
car-washer.enable=true
car-washer.max-task=5
  • 若使用application.yml格式:
# 修改前
carWasher:
  enable: true
  max-task: 5

# 修改后
car-washer:
  enable: true
  max-task: 5

临时兼容方案(不推荐)

如果暂时无法调整命名需要兼容旧配置,可在配置文件中添加以下配置关闭命名校验,该方式不符合Spring Boot官方规范,不建议长期使用:

spring.config.import-check.enabled=false

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.20 22:36:02