zoukankan      html  css  js  c++  java
  • Spring Boot四:配置文件详解properties

    一.配置随机数,使用随机数

    在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文件的优先级

    0?wx_fmt=jpeg

    相同的配置信息在配置在application.properties中,优先级高的生效

    四.其他配置介绍

    #配置tomcat的端口
    server.port=8080
    
    #时间格式化
    spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
    
    #时区设置
    spring.jackson.time-zone=Asia/Chongqing

    0?wx_fmt=jpeg

  • 相关阅读:
    Kubernetes中Pod之间使用虚拟二层网络连接
    ResourceQuota和LimitRange实践指南
    Namespace集群环境的共享与隔离
    K8s生产架构
    K8s常用命令整理+名词解析
    K8s中的pv&&pvc
    Kubernetes保证集群内节点和网络安全
    Kubernetes中网络相关知识
    kubectl常用命令
    物理ceph集群+K8s
  • 原文地址:https://www.cnblogs.com/Java-Road/p/11824718.html
Copyright © 2011-2022 走看看