springboot中获取application.yml中的配置信息

时间:2020-11-12 16:10:42 类型:JAVA
字号:    

配置application.yml

server:
  port: 80
info:
# 站点信息
  webName: 南昌雅腾信息科技有限公司

代码中获取信息

@RestController
@RequestMapping("/bird")
public class Bird {
    @Value("${info.webName}")
    private  String webName;
    @RequestMapping("/fly")
    public String fly(){
        System.out.println(webName);
        return "我要飞翔";
    }
}


<