Ribeye
Ribeye

Reputation: 2177

Spring Properties showing as Null

I have a Spring Boot application, generated by JHipster.

Am trying to add some new properties to the application-dev.yml file but my class is seeing the values null, even after spending some hours with Google.

Added the following to the top of application-dev.yml:

host: 1.2.3.4
port: 5555

In my class I have

@Component
public class ExampleUtils {

    @Value("${host}")
    private String host;

    @Value("${port}")
    private String port;
}

The class is in a new directory under the source root.

Thanks in advance.

Upvotes: 3

Views: 2806

Answers (2)

Pierre Besson
Pierre Besson

Reputation: 740

It is a good practice to add the new properties you add to a @ConfigurationProperties class. At least this way I never had problems adding properties. Have a look at the docs : http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-typesafe-configuration-properties

Upvotes: 1

kuhajeyan
kuhajeyan

Reputation: 11017

in your application.properties set

spring.profiles.active=dev

or when you run the application parse the command line args follows

-Dspring.profiles.active=dev

Upvotes: 2

Related Questions