因此,我尝试根据https://docs.spring.io/spring-boot/docs/current/reference/html/configuration-metadata.html#configuration-metadata-annotation-processor上提供的文档,通过@ConfigurationProperties项生成自己的配置元数据。请注意,我正在使用Spring Boot 2.0和Kotlin。
它工作正常,除了一件事:defaultValue字段没有用我的默认值填充,而是只包含0或false之类的标准值。
我的@ConfigurationProperties文件如下所示:
@Component
@ConfigurationProperties("flowr.epg")
class EpgProperties {
/** Whether or not schedules should be computed/refreshed on (re)start */
var refreshOnRestart = true
/** Number of threads used to store new images */
var nImagesUploadThreads = 10
}
结果如下:
{
"hints": [],
"groups": [
{
"sourceType": "com.taktik.flowr.epg.properties.EpgProperties",
"name": "flowr.epg",
"type": "com.taktik.flowr.epg.properties.EpgProperties"
}
],
"properties": [
{
"sourceType": "com.taktik.flowr.epg.properties.EpgProperties",
"defaultValue": false,
"name": "flowr.epg.refresh-on-restart",
"description": "Whether or not schedules should be computed\/refreshed on (re)start",
"type": "java.lang.Boolean"
},
{
"sourceType": "com.taktik.flowr.epg.properties.EpgProperties",
"defaultValue": 0,
"name": "flowr.epg.n-images-upload-threads",
"description": "Number of threads used to store new images in Ozone",
"type": "java.lang.Integer"
}
}
该文档对于该defaultValue字段有点差劲。难道我做错了什么?是否可以自动填充该defaultValue字段?如果是,我在做什么错了?