英文:
Snakeyaml: Cannot create property for
问题
以下是翻译好的内容:
我有一个YAML文件,需要作为参数传递给Java类。但是它抛出了以下异常:
日志:
Caused by: Cannot create property=heartbeatThreshold for JavaBean=UdsConfigurationBean{jdbcDriverClassString='org.mariadb.jdbc.Driver', sparkConfigFile='spark/spark-local.conf'}
in 'reader', line 15, column 3:
jdbcDriverClassString: org.maria ...
^
Unable to find property 'heartbeatThreshold' on class: MyClass
in 'reader', line 36, column 23:
heartbeatThreshold: 60000000
^
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:292)
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructor.java:171)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:230)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:219)
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:269)
... 12 more
Caused by: org.yaml.snakeyaml.error.YAMLException: Unable to find property 'heartbeatThreshold' on class: MyClass
at org.yaml.snakeyaml.introspector.PropertyUtils.getProperty(PropertyUtils.java:159)
at org.yaml.snakeyaml.introspector.PropertyUtils.getProperty(PropertyUtils.java:148)
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.getProperty(Constructor.java:309)
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:230)
... 16 more
我的分析:
1)MyClass被打包为jar,并且在另一个项目中运行正常,所以应该是我的YAML文件有问题。
2)YAML验证已经通过,所有的变量似乎都在使用camelCase命名法。
3)根据我的研究,PropertyUtils对于抛出此异常有两个检查条件,如果属性值为空(根据日志不是空的),以及isWritable(我不太理解这部分)。
4)对于jdbcDriverClassString,错误指示在名称上,对于heartbeatThreshold值,错误指示在值上。
你能帮我找出问题吗?我会非常感激。
YAML文件:
kafka:
kafkaServers: ${udsKafkaEpfConfigurationBean.kafka.kafkaServers}
kafkaPrincipal: ${udsKafkaEpfConfigurationBean.kafka.kafkaPrincipal}
kafkaKeytab: ${udsKafkaEpfConfigurationBean.kafka.kafkaKeytab}
kafkaEnvironment: ${udsKafkaEpfConfigurationBean.kafka.kafkaEnvironment}
storage:
jdbcDriverClassString: ${memsql.driver}
initializationStoresGeneration: true
heartbeatThreshold: ${MyCLass.kafka.heartbeatThreshold}
英文:
I've a yaml fileto be passed as an argument to the java class. But it throws below exception:
Logs
Caused by: Cannot create property=heartbeatThreshold for JavaBean=UdsConfigurationBean{jdbcDriverClassString='org.mariadb.jdbc.Driver', sparkConfigFile='spark/spark-local.conf'}
in 'reader', line 15, column 3:
jdbcDriverClassString: org.maria ...
^
Unable to find property 'heartbeatThreshold' on class: MyClass
in 'reader', line 36, column 23:
heartbeatThreshold: 60000000
^
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:292)
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructor.java:171)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:230)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:219)
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:269)
... 12 more
Caused by: org.yaml.snakeyaml.error.YAMLException: Unable to find property 'heartbeatThreshold' on class: MyClass
at org.yaml.snakeyaml.introspector.PropertyUtils.getProperty(PropertyUtils.java:159)
at org.yaml.snakeyaml.introspector.PropertyUtils.getProperty(PropertyUtils.java:148)
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.getProperty(Constructor.java:309)
at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:230)
... 16 more
My Analysis:
- MyClass is packaged as jar and it works for another project,so there should be problem with my yaml file.
- Yaml validations has passed and seems all the variables are using camelCase.
- As per my findings, PropertyUtils has 2 checks for this exception to be thrown, if property value is null(which it is not as per logs) and isWritable(I didn't get this part)
- for jdbcDriverClassString, error indication is at name and for heartbeatThreshold value, its at value.
Can you please help me figure it out. I would be really grateful.
Yaml file:
kafka:
kafkaServers: ${udsKafkaEpfConfigurationBean.kafka.kafkaServers}
kafkaPrincipal: ${udsKafkaEpfConfigurationBean.kafka.kafkaPrincipal}
kafkaKeytab: ${udsKafkaEpfConfigurationBean.kafka.kafkaKeytab}
kafkaEnvironment: ${udsKafkaEpfConfigurationBean.kafka.kafkaEnvironment}
storage:
jdbcDriverClassString: ${memsql.driver}
initializationStoresGeneration: true
heartbeatThreshold: ${MyCLass.kafka.heartbeatThreshold}
答案1
得分: 0
对我来说,在yaml中添加Skip Missing Properties属性可以解决这个问题:
Yaml = new Yaml()
修改为:
Representer represent = new Representer()
represent.getPropertyUtils().setSkipMissingProperties(true)
Yaml yaml = new Yaml(represent)
英文:
For me, add Skip Missing Properties property to the yaml fixes the problem:
Yaml = new Yaml()
change to
Representer represent = new Representer()
represent.getPropertyUtils().setSkipMissingProperties(true)
Yaml yaml = new Yaml(represent)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论