SpringBoot unknown property in application.properties

时光怂恿深爱的人放手 提交于 2019-12-05 04:55:12

It's because it's being opened by the STS properties editor which validates properties amongst other things. There's no harm in having it in the application.properties file, you can even add your own meta-data for the property.

http://docs.spring.io/spring-boot/docs/current/reference/html/configuration-metadata.html

I was also having the same warnings in application.properties and looking for a way to get rid of this. Searching for an answer has led me here. So I am posting my answer; it may be useful.

There is no harm in using your custom properties in application.properties. There are two ways to get rid of this -

  1. As mentioned in one of the answers, you can add the meta-data for the custom properties (manually or using quick-fix in STS).

  2. If you don't want to add meta-data, then in STS, go to Window -> preferences -> spring -> boot -> properties editor. Here, select 'unknown property' as ignore. By default, it is warning.

I use this method to add properties in the file applciation.properties.

Add your new property in applciation.properties : default.to.address=nunito.calzada@gmail.com Hover the new property, you'll see a "quickfixes tooltip" which proposes you to add the new property : Create metadata for 'default.to.address'.

Then, browse the class and field you want to bind the property to and add this annotation :

@Value("${default.to.address}")
private String address;

Now your object field should be valued with the property value.

You should try adding these kind of values in Environment, instead application.properties, since you have the option to update the values anytime without doing compile changes / redeploy changes. application.properties could more beneficial for the properties that you never change like database credentials.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!