spring boot配置文件详解

spring boot配置文件详解

application.properties是spring-boot的核心配置文件,这个配置文件基本可以取代我们ssm或者ssh里面的所有的xml配置文件。


当我们启动springboot工程做的第一件事就是加载application.properties属性配置文件。


application.properties虽然有时候是空的,也能正常启动,是因为,application.properties有很多默认配置,这也说明了springboot是一个开箱即用的。也就是约定优于配置的实践。

Springboot有很多默认配置参考springboot文档
比如:编码对中文支持很友好,统一utf-8

spring.messages.encoding=UTF-8 # Message bundles encoding.
server.tomcat.uri-encoding=UTF-8 # Character encoding to use to decode the URI.
spring.freemarker.charset=UTF-8 # Template encoding.
spring.http.encoding.charset=UTF-8 # Charset of HTTP requests and responses. Added to the "Content-Type"

比如:tomcat端口号
server.port=8080 # Server HTTP port.

//pojo中有date类型怎么转string类型就靠这两个配置

spring.jackson.date-format=yyyy-MM-dd HH:mm:ss

spring.jackson.time-zone=Asia/Chongqing

参数间引用

com.niwotaxuexiba.author.name=zhangxueliang
com.niwotaxuexiba.author.sex= male
com.niwotaxuexiba.author.desc=${com.niwotaxuexiba.author.name}  ${com.niwotaxuexiba.author.sex}

随机数

# 随机字符串
com.value=${random.value}
# 随机int
com.number=${random.int}
# 随机long
com.bignumber=${random.long}
# 10以内的随机数
com.test1=${random.int(10)}
# 10-20的随机数
com.test2=${random.int[10,20]}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

学亮编程手记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值