Spring Boot配置特定属性spring.profiles

栏目: Java · 发布时间: 7年前

内容简介:SpringBoot能使用application- {你的自定义profile名称myProfileName} .properties模式添加任何你指定配置文件到其属性文件。要加载特定的配置文件属性文件,我们可以使用命令行选项-Dspring.profiles.active = myProfileName。缺省默认SpringBoot是加载application.properties,无需任何-Dspring.profile.active选项,或使用-Dspring.profiles.active = d

SpringBoot能使用application- {你的自定义profile名称myProfileName} .properties模式添加任何你指定配置文件到其属性文件。

要加载特定的配置文件属性文件,我们可以使用命令行选项-Dspring.profiles.active = myProfileName。

缺省默认SpringBoot是加载application.properties,无需任何-Dspring.profile.active选项,或使用-Dspring.profiles.active = default来加载。默认属性文件也可以命名为application-default.properties。

默认配置文件application.properties中指定的任何属性将被你指定加载的配置文件中的的属性覆盖。

也可以在application.properties中指定激活配置文件。

spring.profiles.active=prod

比如你有三个配置文件:

src/main/resources/application.properties(默认的)

src/main/resources/application-dev.properties(你指定的dev)

src/main/resources/application-prod.properties(你指定的prod)

如果在application.properties中有:

spring.profiles.active=prod

那么SpringBoot将加载application-prod.properties内容。

如果你在代码中使用配置文件中的变量:

@Component
<b>public</b> <b>class</b> ClientBean {
  @Value(<font>"${app.window.width}"</font><font>)
  <b>private</b> <b>int</b> width;
  @Value(</font><font>"${app.window.height}"</font><font>)
  <b>private</b> <b>int</b> height;
</font>

如果application-prod.properties和application.properties都有app.window.width和app.window.height,那么以prod中配置的值为主。

spring.profile.include属性

在application-prod.properties还可以加入

spring.profiles.include=throttling,db

这是无条件地添加活动配置文件(以逗号分隔)。此属性添加的配置文件不会根据某些条件或命令行开关决定是否添加,而是始终无条件添加它们。

上述配置是就加载了:

src/main/resources/application-throttling.properties

src/main/resources/application-db.properties

这两个配置文件中的内容。


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Google's PageRank and Beyond

Google's PageRank and Beyond

Amy N. Langville、Carl D. Meyer / Princeton University Press / 2006-7-23 / USD 57.50

Why doesn't your home page appear on the first page of search results, even when you query your own name? How do other web pages always appear at the top? What creates these powerful rankings? And how......一起来看看 《Google's PageRank and Beyond》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

SHA 加密
SHA 加密

SHA 加密工具