Home > Net >  In a springboot application, how can I read values form application.yml, if I need to use them in my
In a springboot application, how can I read values form application.yml, if I need to use them in my

Time:01-03

Following is my application.yml file

spring:
  mail:
    host: smtp.gmail.com
    port: 587

In one of my Java classes, I want to use the port number, which annotation I can use to achieve the same.

CodePudding user response:

You can use the @Value annotation:

@Value("${spring.mail.port}")
private Integer port;

CodePudding user response:

@Value("${spring.mail.port}")
private String port;
  • Related