SpringBoot unknown property in application.properties
Asked Answered
C

6

23

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

[email protected]

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 ?

Cataldo answered 22/4, 2017 at 18:15 Comment(0)
E
20

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

Evelinevelina answered 22/4, 2017 at 18:21 Comment(0)
A
18

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.

Anosmia answered 6/9, 2018 at 5:6 Comment(2)
It doesn't seem to be possible anymore in STS 4, I've raised an issue about it github.com/spring-projects/sts4/issues/654Agretha
I stand corrected for my last reply : in STS 4.11, you will find this option in Window -> Preferences -> Language Servers -> Spring Language Servers -> Spring Boot Language Servers -> Yaml Editor or Properties Editor.Agretha
M
9

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

Add your new property in application.properties : [email protected] 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.

Mambo answered 22/4, 2017 at 19:45 Comment(0)
B
2

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.

Bakeman answered 23/4, 2017 at 1:45 Comment(0)
H
2

You need to use spring-boot-configuration-processor which will generate the configuration metadata for you.

See the example: https://www.baeldung.com/spring-boot-configuration-metadata

Hill answered 18/4, 2020 at 7:55 Comment(0)
A
1

I had the same problem, even after adding all of the Meta. So, in VsCode setting modify :

"spring-boot.ls.problem.application-properties.PROP_UNKNOWN_PROPERTY": "WARNING"

to

"spring-boot.ls.problem.application-properties.PROP_UNKNOWN_PROPERTY": "IGNORE"
Alsatian answered 17/10, 2023 at 17:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.