我正在通过以下方式传递Spring活动配置文件来运行Spring Boot应用:
spring-boot:run -Dspring.profiles.active=dev
我如何在使用maven创建包时传递spring.profiles.active参数?以下是maven命令:
mvn clean install
我正在通过以下方式传递Spring活动配置文件来运行Spring Boot应用:
spring-boot:run -Dspring.profiles.active=dev
我如何在使用maven创建包时传递spring.profiles.active参数?以下是maven命令:
mvn clean install
spring.profiles.active=@active.profile@
其次,通过Maven传递该值:
mvn clean install -Dactive.profile=dev
当jar/war被打包时,该值将被设置为dev。<profiles>
<profile>
<id>dev</id>
<properties>
<active.profile>dev</active.profile>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<active.profile>test</active.profile>
</properties>
</profile>
</profiles>
接着运行:
mvn clean install -Pdev
Maven是一个构建工具,它唯一能够修改构建后运行时行为的方式是使用它的(构建时间)配置文件。这不应与Spring的运行时配置文件混淆,后者是指令,指导Spring容器以特定方式启动应用程序。
换句话说,spring.profiles.active
参数不会被Maven“烘焙”到war文件中,您仍然需要在启动应用程序时传递它,无论是通过命令行参数、配置文件或任何您的servlet容器提供的机制。
对于包,您可以将安装替换为包
mvn clean package -P dev
您可以使用环境变量。
export SPRING_PROFILES_ACTIVE=some,test,profiles
mvn spring-boot:run
mvn clean install -Dspring.profiles.active=dev
? 请将上述代码翻译成中文。 - Tunaki