getting Could not resolve placeholder while reading yml values in spring boot

Viewed 1760

I'm using spring boot and using this value in my application.yml

config:
  username: abc
  password: xyz

In my class, I'm utilizing it this way -

@Value("${config.username}")
    private String username;

I'm getting the following error -

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'config.username' in value "${config.username}"

However if I use this in my application.yml file, it works. Can you please tell me what I'm doing wrong here?

config.username: abc
config.password: xyz
2 Answers

check your placeholder is Tab or Space ? make sure no Tab in your yml file.

was facing the same problem when trying to read from application.yml file instead of application.properties file. maven clean & then maven install resolved the issue for me.

Related