You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 3原生可执行文件未读取指定Profile问题

Spring Boot 3原生镜像Profile不生效问题解决

Spring Boot 3原生镜像完全支持Profile功能,你的问题出在运行原生可执行文件时的参数传递方式错误,而非功能不支持。

问题原因

原生可执行文件是编译后的本地二进制程序,不是JAR包,因此不能用JVM风格的-D参数传递系统属性。-Dspring.profiles.active=local这种写法只适用于运行JAR包的场景,对原生可执行文件无效。

正确的运行方式

有两种可行的方式指定激活的Profile:

  1. 使用Spring Boot命令行参数格式
    直接用--前缀指定配置项:
./target/<app-executable> --spring.profiles.active=local
  1. 使用环境变量
    通过环境变量传递Profile配置:
SPRING_PROFILES_ACTIVE=local ./target/<app-executable>

补充说明

你构建时添加的-Dspring.profiles.active=local是传递给Maven构建过程的参数,不会将该Profile嵌入到原生镜像中,因此运行时仍需明确指定要激活的Profile。另外,你提供的application.properties中多Profile的分隔写法(#---)是Spring Boot的标准用法,没有问题。

内容的提问来源于stack exchange,提问作者Ladu anand

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 13:10:24