Caused by: org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'foodProperties': Could not bind properties to 'FoodProperties' : prefix=configuration.food_properties, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.source.InvalidConfigurationPropertyNameException: Configuration property name 'configuration.food_properties' is not valid
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.bind
Component 类配置如下,此处一开始与配置文件关联的prefix为驼峰命名(foodProperties),引发上面的错误;
@Component
@ConfigurationProperties(prefix = "configuration.foodProperties")
@Data
public class FoodProperties {
private String name ;
}
配置文件:
configuration:
foodProperties:
name: MilkTea
经测试,得出与配置文件关联的prefix不支持驼峰命名和蛇形命名(下划线)。
将Component类和配置文件中的foodProperties改为food,即可解决该错误。