Spring Boot系列教程四:配置文件详解properties
2017-01-08 17:53
1096 查看
一.配置随机数,使用随机数
在application.properties文件添加配置信息#32位随机数 woniu.secret=${random.value} #随机整数 woniu.number=${random.int} #指定范围随机数 woniu.limitnumber=${random.int[0,9]}
controller类中使用这些随机数
package com.woniu.controller; import java.util.HashMap; import java.util.Map; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping(value=("/web")) public class WebController { @Value(value="${woniu.secret}") private String uuid; @Value(value="${woniu.number}") private int randomID; @Value(value="${woniu.limitnumber}") private int limitnumber; @RequestMapping(value="/index") public Map<String, Object> Index(){ Map<String, Object> map = new HashMap<String, Object>(); map.put("uuid", uuid); map.put("randomID", randomID); map.put("limitnumber", limitnumber); return map; } }
二.属性占位符
使用application.properties配置文件中先前定义的值woniu.name="woniu" woniu.desc=${woniu.name} is a domain name
三.application.properties文件的优先级
相同的配置信息在配置在application.properties中,优先级高的生效
四.其他配置介绍
#配置tomcat的端口 server.port=8080 #时间格式化 spring.jackson.date-format=yyyy-MM-dd HH:mm:ss #时区设置 spring.jackson.time-zone=Asia/Chongqing
工程springboot_properties下载地址:点击打开链接
spring boot讨论群:611262656,一键加群:点击加群
更多技术文章请关注微信公众号“Java架构师之路”:
相关文章推荐
- Spring Boot系列教程四:配置文件详解properties
- Spring Boot系列教程五:使用properties配置文件实现多环境配置
- Spring Boot系列教程五:使用properties配置文件实现多环境配置
- Spring Boot系列教程五:使用properties配置文件实现多环境配置
- SpringBoot非官方教程 | 第二篇:Spring Boot配置文件详解
- 企业级 SpringBoot 教程 (二)Spring Boot配置文件详解
- (三)SpringBoot之配置文件详解:Properties和YAML
- (三)SpringBoot之配置文件详解:Properties和YAML
- 详解Spring Boot加载properties和yml配置文件
- SpringBoot非官方教程 | 第二篇:Spring Boot配置文件详解
- Spring Boot基础3-配置文件详解:Properties和YAML
- Spring Boot 配置文件详解:Properties和YAML
- Spring Boot -- 配置文件详解:Properties 和 YAML
- Spring Boot 配置文件详解:Properties和YAML
- SpringBoot非官方教程 | 第二篇:Spring Boot配置文件详解
- Spring Boot系列教程四:配置文件详解properties
- Spring Boot系列教程四:配置文件详解properties
- Spring Boot教程(十六)属性配置文件详解(1)
- SpringBoot非官方教程 | 第二篇:Spring Boot配置文件详解
- (转) SpringBoot非官方教程 | 第二篇:Spring Boot配置文件详解