eclipse “是一个未知属性”:Spring 的 application.properties 中的自定义属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31857598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"is an unknown property": custom properties in Spring's application.properties
提问by maligree
Sorry if this a trivial thing, I'm hacking out on an abandoned project and trying to add a custom property to the projects application.properties
file.
对不起,如果这是一件微不足道的事情,我正在破解一个废弃的项目并尝试将自定义属性添加到项目application.properties
文件中。
The properties actually work fine (i.e. they are properly resolved when doing @Value("${foo.config.someValue"})
) but Eclipse insists on telling me this:
这些属性实际上工作正常(即它们在执行时正确解析@Value("${foo.config.someValue"})
)但 Eclipse 坚持告诉我这一点:
Pressing tab does nothing at all.
按 Tab 什么也不做。
How can I make this go away? Can I define my custom properties somewhere? Or maybe this isn't the way at all to add custom configuration properties?
我怎样才能让它消失?我可以在某处定义我的自定义属性吗?或者这根本不是添加自定义配置属性的方法?
回答by whistling_marmot
Since STS 3.5.4, you should be able to get rid of this warning, and have it replaced by useful 'hover-over' text by using java-doc on an @ConfigurationProperties
bean to auto-generate configuration meta-data. You should be able to do this with application.properties or, since 3.7.0, application.yml, (but so far, I can't get it to work with either).
从STS 3.5.4 开始,您应该能够摆脱此警告,并通过在@ConfigurationProperties
bean上使用 java-doc自动生成配置元数据,将其替换为有用的“悬停”文本。您应该可以使用 application.properties 或从3.7.0 开始使用 application.yml 来执行此操作(但到目前为止,我都无法使用它)。
回答by Matt C
There is an Eclipse Quick Fixto deal with the warning you mention available in STS since the 3.7.1.RELEASE https://issuetracker.springsource.com/browse/STS-4206
自 3.7.1.RELEASE https://issuetracker.springsource.com/browse/STS-4206起,有一个Eclipse Quick Fix可以处理您在 STS 中提到的警告
Otherwise, assuming you have defined your properties as @ConfigurationProperties
, then you just need to ensure you have spring-boot-configuration-processor
as an optional dependency as discussed here https://docs.spring.io/spring-boot/docs/current/reference/html/configuration-metadata.html#configuration-metadata-annotation-processor
否则,假设您已将属性定义为@ConfigurationProperties
,那么您只需要确保您具有spring-boot-configuration-processor
可选的依赖项,如此处讨论的https://docs.spring.io/spring-boot/docs/current/reference/html/configuration-metadata .html#configuration-metadata-annotation-processor
回答by Sanjay
Your project might be having configuration metadata, whether generatedor manual. If so, you would need to add your the metadata pertaining to the new property, and re-build the project.