[英]What's the difference between -Drun.profiles and -Dspring.profiles.active on Spring?
I'm trying to understand the difference in Spring between -Drun.profiles
and -Dspring.profiles.active
. 我试图了解
-Drun.profiles
和-Dspring.profiles.active
在Spring中的-Dspring.profiles.active
。
Another answer in SO does not explain so much about the difference. SO中的另一个答案并没有对差异做太多解释。
In my tests, both of them can be used to select a profile: 在我的测试中,它们都可以用来选择配置文件:
mvn spring-boot:run -Drun.profiles=prod
or 要么
mvn spring-boot:run -Dspring.profiles.active=prod
So, what's the difference? 那么,有什么区别呢?
spring.profiles.active
is one of the properties that Spring Boot applications support out of the box. spring.profiles.active
是Spring Boot应用程序开箱即用支持的属性之一。 Its used to specify at the level of Spring Boot application which profiles should be run. 它用于在Spring Boot应用程序级别指定应运行的配置文件。
Spring Boot supports many different properties, a full list can be found here . Spring Boot支持许多不同的属性,可以在此处找到完整列表。
Now, you won't find run.profiles
among these properties, because its just a property that Spring Boot Maven plugin supports (and yes, it 'translates' it to the list of profiles to be used as well, so these properties might look similar), but the point is that -Drun.profiles
will only work if you start the spring boot application with Maven plugin. 现在,您将不会在这些属性中找到
run.profiles
,因为它只是Spring Boot Maven插件支持的一个属性(是的,它也将其“转换”为要使用的配置文件列表,因此这些属性可能看起来像类似),但要点是-Drun.profiles
仅在使用Maven插件启动spring boot应用程序时才有效。
In production, however, the chances are that there won't be Maven at all, and the application will run as is (as a big jar) or even packed as Docker image or something. 但是,在生产中,完全没有Maven的机会,并且该应用程序将按原样(作为一个大罐子)运行,甚至打包为Docker映像或其他东西。 So for non maven-plugin usage you should use
spring.profiles.active
因此,对于非Maven插件,应使用
spring.profiles.active
The last point, that even in Maven --spring.profiles.active
can be used, but it doesn't work out of the box. 最后一点,即使在Maven中也可以使用
--spring.profiles.active
,但它开箱即用。 You should pass this parameter like this: 您应该像这样传递此参数:
mvn spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=production"
See this item in Github . 请参阅Github中的此项 。
Hope this clarifies the differences between the two. 希望这可以澄清两者之间的差异。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.