Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read from application.yml file in Java

I wrote an e mail program. But I had to change the some configs, so in my project I need to know how to read from yaml for my loginUrl

my code below;

  userNotificationEmail.setIsActive("F");
  userNotificationEmailRepository.save(userNotificationEmail);
  activationResultType.setResultCode(ActivationResultCode.SUCCESSFUL);
  activationResultType.setUser(userMapper.fromUser(userEntity));
  activationResultType.setLoginUrl(loginUrl);
  return activationResultType;
like image 540
cocaColaPha Avatar asked Oct 22 '25 21:10

cocaColaPha


1 Answers

If your key is loginUrl (inside your yaml file), you can inject its value with the @Value annotation, inside a Spring component.

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

If it's a second level property, the path is @Value("${yourFirstKey.loginUrl}").

More documentation about reading YAML files with Spring Boot.

like image 192
Thoomas Avatar answered Oct 25 '25 12:10

Thoomas