Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 282
Ribeye Avatar asked Apr 28 '26 14:04

Ribeye


1 Answers

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
like image 142
kuhajeyan Avatar answered May 01 '26 06:05

kuhajeyan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!