SpringBoot unknown property in application.properties

一世执手 提交于 2019-12-10 03:03:34

问题


I've generated a Spring Boot web application using Spring Initializr, using embedded Tomcat + Thymeleaf template engine.

I put this property in my application.properties

default.to.address=nunito.calzada@gmail.com

I am using Spring Tool Suite Version: 3.8.4.RELEASE as a development environment, but I got this warning in the Editor 'default.to.address' is an unknown property.

Should I put this property in another property file ?


回答1:


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




回答2:


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.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/43562880/springboot-unknown-property-in-application-properties

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