简体   繁体   English

在Spring上-Drun.profiles和-Dspring.profiles.active有什么区别?

[英]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.

相关问题 `java -Dspring.profiles.active -jar xxx.jar` 和 `java -jar xxx.jar --spring.profiles.active` 有什么区别 - What is the difference between `java -Dspring.profiles.active -jar xxx.jar` and `java -jar xxx.jar --spring.profiles.active` 尝试执行Spring Boot jar时,“-Drun.profiles = ..”不起作用 - “-Drun.profiles=..” is not working when trying to execute Spring Boot jar @Profile在没有Spring Boot的情况下不起作用(-Dspring.profiles.active与Maven) - @Profile does not work without Spring Boot (-Dspring.profiles.active with maven) Wildfly 10 我可以在standalone.conf.bat 中设置-Dspring.profiles.active 吗? - Wildfly 10 Can I set -Dspring.profiles.active in standalone.conf.bat? 在带有m2e的Eclipse中,“选择活动配置文件”和“运行配置:配置文件”有什么区别? - What is the difference between “Select Active Profiles” and “Run Configuration: profiles” in Eclipse with m2e? Spring - 多个配置文件处于活动状态 - Spring - Multiple Profiles active 如何使用 maven 配置文件设置 spring 活动配置文件 - How to set spring active profiles with maven profiles 如何让Spring打印出哪些弹簧轮廓是活动的? - How to get Spring to print out what spring profiles are active? spring.profiles.active 不兑现 - spring.profiles.active not honoured 通过 Spring 或通过 Maven/Gradle 等构建工具的配置文件有什么区别 - What is the difference between Profiles via Spring or via a build tool like Maven/Gradle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM