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

ddd*_*ddd 8 eclipse spring jvm web-services maven

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

application-dev.properties
application-qa.properties
application-stg.properties
application-prod.properties
Run Code Online (Sandbox Code Playgroud)

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

-Dspring.profiles.active=prod
Run Code Online (Sandbox Code Playgroud)

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

编辑:我在下面设置了JVM选项运行配置.因为我从tomcat得到以下错误,所以当我将它部署为战争时,似乎没有被maven接收:

Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception
Run Code Online (Sandbox Code Playgroud)

has*_*nae 9

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


Ark*_*yay 7

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