[英]Custom application properties in spring boot using IntelliJ
I'm trying to use application properties, other than application.properties, say application_local.properties
within resources directory.我正在尝试使用应用程序属性,而不是 application.properties,比如资源目录中的application_local.properties
。
So that I can have 2 properties files, one for local and other the server.这样我就可以有 2 个属性文件,一个用于本地,另一个用于服务器。
As mentioned in many blogs, I should use below command:正如许多博客中提到的,我应该使用以下命令:
spring-boot:run -Dspring.config.location=/Users/myuser/work/MyProject/my-app/src/main/resources/application_local.properties
But this is not working, it is still fetching values from application.properties.但这不起作用,它仍在从 application.properties 获取值。
What am I missing, please suggest?我缺少什么,请提出建议?
Thanks谢谢
1- Follow the naming convention application-{profile}.properties 1- 遵循命名约定 application-{profile}.properties
- application-local.properties应用程序-local.properties
2-set profile 2 套配置文件
- -Dspring.profiles.active=local -Dspring.profiles.active=本地
Briefly, you can use these two links:简而言之,您可以使用以下两个链接:
-Dspring.profile.location
takes directory as input. -Dspring.profile.location
将目录作为输入。 The purpose of this property is to specify additional directory location to keep your property files.此属性的目的是指定额外的目录位置来保存您的属性文件。
You are using property file name in your command.您在命令中使用了属性文件名。
Refer to detailed @ Answer at other thread here请参阅此处其他线程的详细@Answer
Instead you can use as suggested by @mehardad相反,您可以按照@mehardad 的建议使用
The -D option will send parameters to Java virtual machine. -D 选项会将参数发送到 Java 虚拟机。 In order to send parameters to Spring boot, the command option of '--' must be used.为了向 Spring boot 发送参数,必须使用命令选项“--”。
Example:例子:
Suppose, there is an option named 'spring.profiles.active' defined in the application.properties file as follows:假设在 application.properties 文件中定义了一个名为“spring.profiles.active”的选项,如下所示:
spring.profiles.active=dev spring.profiles.active=dev
This option can be overwritten using command line parameter as follows:可以使用命令行参数覆盖此选项,如下所示:
java -jar application.jar --spring.profiles.active=prod
Use Spring profiles and choose at runtime, locally would使用 Spring 配置文件并在运行时选择,本地将
-Dspring.profiles.active=local
The property file should be called application-local.properties
属性文件应称为application-local.properties
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.