Spring 上的 -Drun.profiles 和 -Dspring.profiles.active 有什么区别?
What's the difference between -Drun.profiles and -Dspring.profiles.active on Spring?
我想了解 -Drun.profiles
和 -Dspring.profiles.active
之间 Spring 的区别。
另一个answer in SO并没有解释太多不同之处。
在我的测试中,它们都可以用于select一个配置文件:
mvn spring-boot:run -Drun.profiles=prod
或
mvn spring-boot:run -Dspring.profiles.active=prod
所以,有什么区别?
spring.profiles.active
是 Spring 启动应用程序开箱即用支持的属性之一。它用于在 Spring 启动应用程序级别指定哪些配置文件应为 运行。
Spring Boot 支持许多不同的属性,可以找到完整列表 here。
现在,您不会在这些属性中找到 run.profiles
,因为它只是 Spring Boot Maven 插件支持的 属性(是的,它 'translates'它也添加到要使用的配置文件列表中,因此这些属性可能看起来很相似),但重点是 -Drun.profiles
仅在您使用 Maven 插件启动 spring 引导应用程序时才有效。
然而,在生产中,可能根本不会有 Maven,应用程序将 运行 按原样(作为一个大罐子)甚至打包为 Docker 图像或者其他的东西。所以对于非 maven-plugin 用法,你应该使用 spring.profiles.active
最后一点,即使在 Maven 中 --spring.profiles.active
也可以使用,但它不是开箱即用的。您应该像这样传递此参数:
mvn spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=production"
希望这能澄清两者之间的区别。
我想了解 -Drun.profiles
和 -Dspring.profiles.active
之间 Spring 的区别。
另一个answer in SO并没有解释太多不同之处。
在我的测试中,它们都可以用于select一个配置文件:
mvn spring-boot:run -Drun.profiles=prod
或
mvn spring-boot:run -Dspring.profiles.active=prod
所以,有什么区别?
spring.profiles.active
是 Spring 启动应用程序开箱即用支持的属性之一。它用于在 Spring 启动应用程序级别指定哪些配置文件应为 运行。
Spring Boot 支持许多不同的属性,可以找到完整列表 here。
现在,您不会在这些属性中找到 run.profiles
,因为它只是 Spring Boot Maven 插件支持的 属性(是的,它 'translates'它也添加到要使用的配置文件列表中,因此这些属性可能看起来很相似),但重点是 -Drun.profiles
仅在您使用 Maven 插件启动 spring 引导应用程序时才有效。
然而,在生产中,可能根本不会有 Maven,应用程序将 运行 按原样(作为一个大罐子)甚至打包为 Docker 图像或者其他的东西。所以对于非 maven-plugin 用法,你应该使用 spring.profiles.active
最后一点,即使在 Maven 中 --spring.profiles.active
也可以使用,但它不是开箱即用的。您应该像这样传递此参数:
mvn spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=production"
希望这能澄清两者之间的区别。