在我的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.
在上述情况下,env-value的值将为local/devl/test/prod
In above case, env-value will have values as local/devl/test/prod
在哪里设置环境值文件?对于本地,我可以通过sts
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.properties和application-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文件
发布评论