Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpringBoot unknown property in application.properties

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 ?

like image 674
Nunyet de Can Calçada Avatar asked Apr 22 '17 18:04

Nunyet de Can Calçada


People also ask

How does spring Boot find application properties?

Spring Boot automatically loads the application. properties whenever it starts up. You can dereference values from the property file in your java code through the environment. Put a property in the application.

Can I change application properties at runtime spring boot?

To change properties in a file during runtime, we should place that file somewhere outside the jar. Then we tell Spring where it is with the command-line parameter –spring. config. location=file://{path to file}.

How do I set environment specific properties in spring boot?

Simply add an application-[profile]. properties file and specify the profiles to use using the spring. profiles. active property.


4 Answers

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

like image 114
Darren Forsythe Avatar answered Oct 22 '22 02:10

Darren Forsythe


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.

like image 15
Akash Avatar answered Oct 22 '22 00:10

Akash


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.

like image 4
Takyon Avatar answered Oct 22 '22 02:10

Takyon


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.

like image 2
CodersDream Avatar answered Oct 22 '22 01:10

CodersDream