Spring Boot应用程序中的特定于环境的application.properties文件 [英] Environment Specific application.properties file in Spring Boot application

查看:81
本文介绍了Spring Boot应用程序中的特定于环境的application.properties文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Spring Boot应用程序中,我想创建特定于环境的属性文件.我在战争中应用程序的包装类型,我正在嵌入式tomcat中执行它.我使用sts并从sts本身执行main.

In my Spring Boot application, i want to create environment specific properties file. The packaging type of my application in war and i am executing it in embedded tomcat. I use sts and execute the main from sts itself.

  1. 我可以拥有特定于环境的属性文件,例如application-$ {env-value} .properties吗?

在上述情况下,env-value的值将为local/devl/test/prod

In above case, env-value will have values as local/devl/test/prod

  1. 在哪里设置环境值文件?对于本地,我可以通过sts

  1. Where to set the env-value file? For local, i can set it as the jvm argument through sts

谁在Spring Boot应用程序中读取application.properties.

Who reads the application.properties in Spring Boot application.

如何加载特定于环境的属性文件?例如-如果我在特定于环境的属性文件中设置数据库uid,pwd,schema等,那么在这种情况下,数据源将能够理解其中的属性?

How to load the environment specific properties file? For ex - if i set the database uid,pwd, schema etc in environment specific property file, in that case will the datasource be able to understand the properties in it?

我可以同时使用application.properties和application-local.properties文件吗?

Can i use application.properties and application-local.properties file at same time?

推荐答案

Spring Boot已经

Spring Boot already has support for profile based properties.

只需添加application-[profile].properties文件,然后使用spring.profiles.active属性指定要使用的配置文件.

Simply add an application-[profile].properties file and specify the profiles to use using the spring.profiles.active property.

-Dspring.profiles.active=local

这将从application.propertiesapplication-local.properties的第一个优先属性中加载后者.

This will load the application.properties and the application-local.properties with the latter overriding properties from the first.

这篇关于Spring Boot应用程序中的特定于环境的application.properties文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆