通过Maven构建中的Spring配置文件 [英] Pass Spring profile in maven build

查看:252
本文介绍了通过Maven构建中的Spring配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过传递如下所示的spring活动配置文件来运行spring boot应用程序:

I am running the spring boot app by passing the spring active profile like below:

spring-boot:run -Dspring.profiles.active=dev

但是在使用maven创建软件包时如何传递spring.profiles.active.以下是maven命令:

But how do I pass the spring.profiles.active when creating the package using maven. Following is the maven command:

mvn clean install

推荐答案

Maven是一个构建时工具,使其修改已构建工件的最终运行时行为的唯一方法是使用其( build-时间)配置文件.请勿将此与Spring的 runtime 配置文件混淆,这些配置文件是指示Spring容器以特定方式引导应用程序的参数.

Maven is a build-time tool, the only way to make it modify the eventual runtime behaviour of the built artifact is to use its (build-time) profiles. This must not be confused with Spring's runtime profiles which are parameters instructing the Spring container to bootstrap application in a specific way.

换句话说,spring.profiles.active参数不会被maven烘焙"到战争文件中,您仍然需要在启动应用程序时通过命令行参数或配置文件将其传递给它.或Servlet容器提供的任何机制.

In other words, the spring.profiles.active parameter doesn't get "baked into" the war file by maven, you'll still need to pass it when starting the application up, be it via command-line parameters or configuration file or whatever mechanism your servlet container offers.

这篇关于通过Maven构建中的Spring配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆