博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
springboot-项目属性配置
阅读量:6938 次
发布时间:2019-06-27

本文共 1759 字,大约阅读时间需要 5 分钟。

hot3.png

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();    }}

效果:

 

 

转载于:https://my.oschina.net/liusonghuang/blog/1456338

你可能感兴趣的文章
理解Java动态代理(1)—找我还钱?我出钱要你的命
查看>>
前后端分离?
查看>>
打砖块代码解析
查看>>
Qt creator使用笔记
查看>>
C# socket 解析http 协议
查看>>
webpack 的异步组件 生成commonchunks
查看>>
linux环境搭建seafile客户端自动上传文件
查看>>
抽象类
查看>>
js logger
查看>>
hdu6376 度度熊剪纸条 思维
查看>>
清空日志的三种方法
查看>>
传输文件过程中遇到异常被中断
查看>>
JBPM对象主键生成机制
查看>>
11-08笔记图
查看>>
接口里面的静态方法--痒啊
查看>>
mongodb分享(二)
查看>>
template模板的使用方法
查看>>
想成为一个高效的Web开发者吗?来看看大牛分享的经验吧~ #精选JAVASCRIPT前端开发...
查看>>
删除某个文件夹下的所有文件
查看>>
多线程 -- 实现秒抓
查看>>