1.application.yml
server: port: 8080boy: hlsBirth: 1994出生 hlsAge: 23
2.HlsApplication
package com.hls;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class HlsApplication { public static void main(String[] args) { SpringApplication.run(HlsApplication.class, args); }}3.Boyproperties
package com.hls;import org.springframework.boot.context.properties.ConfigurationProperties;import org.springframework.context.annotation.Configuration;import org.springframework.stereotype.Component;/** * Created by huangliusong on 2017/7/18. */@Component@ConfigurationProperties(prefix = "boy")public class Boyproperties { private String hlsBirth; private Integer hlsAge; public String getHlsBirth() { return hlsBirth; } public void setHlsBirth(String hlsBirth) { this.hlsBirth = hlsBirth; } public void setHlsAge(Integer hlsAge) { this.hlsAge = hlsAge; } public Integer getHlsAge() { return hlsAge; }}4.HelloController
package com.hls;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Value;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RestController;/** * Created by huangliusong on 2017/7/18. */@RestControllerpublic class HelloController { @Autowired private Boyproperties boyproperties; @RequestMapping(value="/hls",method = RequestMethod.GET) public String say (){ return boyproperties.getHlsBirth()+"====="+boyproperties.getHlsAge(); }}
效果: