运行 mvn install 时如何指定 spring.profiles.active

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39081945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 01:11:38  来源:igfitidea点击:

How to specify spring.profiles.active when I run mvn install

eclipsespringweb-servicesmavenjvm

提问by ddd

In this web application with Spring, I created several application-property files for different deploy environment. They specify different db connection configs.

在这个带有 Spring 的 Web 应用程序中,我为不同的部署环境创建了几个应用程序属性文件。他们指定不同的数据库连接配置。

application-dev.properties
application-qa.properties
application-stg.properties
application-prod.properties

The recommended way according to spring docis to set spring.profiles.active as JVM option at run time, for example:

根据spring 文档推荐的方法是在运行时将 spring.profiles.active 设置为 JVM 选项,例如:

-Dspring.profiles.active=prod

However what should I do for deploying the application as war using mvn install. How should I set the spring profile? I am using Eclipse.

但是,我应该怎么做才能使用 mvn install 将应用程序部署为 war。我应该如何设置弹簧轮廓?我正在使用 Eclipse。

EDIT: I set the JVM option under run configuration. It does not seem to get picked up by maven when I deploy it as a war though since I got the following error from tomcat:

编辑:我在运行配置. 当我将它部署为War时,它似乎没有被 maven 接收,因为我从 tomcat 收到以下错误:

Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception

采纳答案by hasnae

Under Run->run configurations, select your maven launch configuration, then select the JRE tab, and type your argument in the VM arguments text area.

在运行->运行配置下,选择您的 Maven 启动配置,然后选择 JRE 选项卡,并在 VM 参数文本区域中键入您的参数。

回答by Randy Orton

Under Run Configuration > go to Environments tab and then add your property values for more please refer image below :Eclipse Environment SetUp

在“运行配置”>“环境”选项卡下,然后添加您的属性值以获取更多信息,请参阅下图:Eclipse 环境设置