Spring Boot配置难得的使用解释说明(小猪佩奇:配置加载是有优先级的)

本文详细介绍了Spring Boot的配置加载顺序,包括从官方文档、classpath中的额外jar、自定义属性、命令行参数、random.*属性、属性文件、YAML格式配置、@ConfigurationProperties绑定、Java配置类、Spring Profiles以及CommandLineRunner接口的使用。强调了配置管理在项目中的重要性,并给出了多个配置示例。
摘要由CSDN通过智能技术生成

SpringBoot的所有配置项都是可以在官方文档找到的:官方配置详解
介绍:
Appendix A. Common application properties
Various properties can be specified inside your application.properties file, inside your application.yml file, or as command line switches. This appendix provides a list of common Spring Boot properties and references to the underlying classes that consume them.
(丰富的配置都可以被在application.properties、application.yml指定或者是命令行中切换,附录中提供了一些常用的配置List集合和这些配置的作用)
下面是附录的一部分
这里写图片描述
1、Property contributions can come from additional jar files on your classpath, so you should not consider this an exhaustive list. Also, you can define your own properties.
(配置的应用可以来自于你的classpath中的其他配置文件,你可以不参考附录中的配置,而去指定你自定义的配置)

2、This sample file is meant as a guide only. Do not copy and paste the entire content into your application. Rather, pick only the properties that you need.
(附录中的配置参数只是仅供参考的,不要整个粘贴复制到你项目中的配置项中去,更重要的是,需要去选择你需要修改的配置项进行合适的修改)

3、配置项的引用

在application.properties中的各个参数之间可以直接通过“${keyname}”引用来使用。
在application.properties中也可以通过“@keyname@”来引用pom文件中的元素节点值,例如:

3.1
pom文件中有如下定义:

<properties>
    <project.name >easy-springboot-demo </ project.name >
    <project.version>1.0</ project.version >
</properties>

3.2
则在application.properties文件中可以通过如下方式引用:

# 项目名称
com.easy.springboot.project.name = @project.name@
# 项目版本
com.easy.springboot.project.version = @project.version@

4、随机数属性value
在一些情况下,有些参数我们需要希望它不是一个固定的值,Spring Boot的属性配置文件中可以通过${random}来产生int值、long值或者string字符串,来支持属性的随机值。

# 随机字符串
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值