Spring boot基础:配置文件配置变量

一、配置

  resources下面application.properties

1、普通配置

  resources下面application.properties,比如写上:server.port=9090,那么启动端口就是9090了

2、自定义配置

3、配置变量的引用

4、随机值配置:如果参数是随机的,可以通过在配置文件里面配

5、随机端口配置:避免端口冲突的问题

#server.port=9090
server.port=${random.int[1024,9999]}//随机端口
gwf.num=${random.int}//随机数
gwf.hello=hello//自定义
gwf.name = gwf  ${gwf.hello}  ${gwf.num}//配置变量的引用
@RestController
public class HelloController {
    @Value("${gwf.name}")
    private String msg;
    @RequestMapping("/hello")
    public String hello() {
        return this.msg;
    }
}

  使用就是通过注解  @Value("${}")  引用,有点类似jsp变量取值的方式

二、yml配置文件

  YAML是一种写配置文件的语言,它是一种天然的树状结构

三、日志配置文件

  logback.xml,可百度查询

猜你喜欢

转载自www.cnblogs.com/goloving/p/9142018.html
今日推荐