Failed to bind properties under … 的几种报错各长什么样?枚举写错会不会列出合法值?拼错属性名怎么发现?ignoreUnknownFields = false 对哪些来源有效?这篇在 Spring Boot 4.0.8 上逐个触发。
启动成功:AppProps[port=8080, name=demo, timeout=PT5S, color=RED, maxSize=10, tags=null]
只给 app.name,其余用默认值。
启动失败:BindException
报告:Failed to bind properties under 'app.port' to int:
报告:Property: app.port
报告:Value: "abc"
报告:Origin: "app.port" from property source "systemProperties"
报告:Reason: failed to convert java.lang.String to @org.springframework.boot.context.properties.bind.DefaultValue int (caused by java.lang.NumberFormatException: For input string: "abc")
报告:Action:
报告:Update your application's configurationint 字段给 abc,报告给出属性名、值与来源。
启动失败:BindException
报告:Failed to bind properties under 'app.color' to demo.Color:
报告:Property: app.color
报告:Value: "PURPLE"
报告:Origin: "app.color" from property source "systemProperties"
报告:Reason: failed to convert java.lang.String to @org.springframework.boot.context.properties.bind.DefaultValue demo.Color (caused by java.lang.IllegalArgumentException: No enum constant demo.Color.PURPL
报告:Action:
报告:Update your application's configuration. The following values are valid:
报告:GREEN
报告:RED报告列出合法取值。
启动失败:BindException
报告:Failed to bind properties under 'app.timeout' to java.time.Duration:
报告:Property: app.timeout
报告:Value: "10x"
报告:Origin: "app.timeout" from property source "systemProperties"
报告:Reason: failed to convert java.lang.String to @org.springframework.boot.context.properties.bind.DefaultValue java.time.Duration (caused by java.lang.IllegalArgumentException: Unknown unit 'x')
报告:Action:
报告:Update your application's configuration只指出 Unknown unit。
启动失败:BindException
报告:Binding to target demo.AppProps failed:
报告:Property: app.maxSize
报告:Value: "0"
报告:Origin: "app.max-size" from property source "systemProperties"
报告:Reason: must be greater than or equal to 1
报告:Action:
报告:Update your application's configuration
-- 同一节的另一组
启动失败:BindException
报告:Binding to target demo.AppProps failed:
报告:Property: app.name
报告:Value: ""
报告:Origin: "app.name" from property source "systemProperties"
报告:Reason: must not be blank
报告:Action:
报告:Update your application's configuration@Min 与 @NotBlank 的报告。
启动成功:AppProps[port=8080, name=demo, timeout=PT5S, color=RED, maxSize=10, tags=null]
-- 同一节的另一组
启动失败:BindException
报告:Binding to target [Bindable@… type = demo.StrictProps, value = 'none', annotations = array<Annotation>[@org.springframework.boot.context.properties.ConfigurationProperties(ignoreInvalidFields=false, i
报告:Property: strict.hots
报告:Value: "h"
报告:Origin: URL [file:<源码> - 1:13
报告:Reason: The elements [strict.hots] were left unbound.
报告:Action:
报告:Update your application's configuration
-- 同一节的另一组
启动成功:AppProps[port=8080, name=demo, timeout=PT5S, color=RED, maxSize=10, tags=null]默认静默忽略;strict 对配置文件有效,对 -D 无效。
启动成功:AppProps[port=8080, name=demo, timeout=PT5S, color=RED, maxSize=21, tags=null] -- 同一节的另一组 启动成功:AppProps[port=8080, name=demo, timeout=PT5S, color=RED, maxSize=22, tags=null] -- 同一节的另一组 启动成功:AppProps[port=8080, name=demo, timeout=PT5S, color=RED, maxSize=23, tags=null] -- 同一节的另一组 启动成功:AppProps[port=8080, name=demo, timeout=PT5S, color=RED, maxSize=24, tags=null] -- 同一节的另一组 启动成功:AppProps[port=8080, name=demo, timeout=PT5S, color=RED, maxSize=25, tags=null]
五种写法都行。
启动成功:AppProps[port=8080, name=demo, timeout=PT5S, color=RED, maxSize=10, tags=[a, b]] -- 同一节的另一组 启动成功:AppProps[port=8080, name=demo, timeout=PT5S, color=RED, maxSize=10, tags=[x, y]]
下标写法与逗号写法。