SpringBoot项目@spring.active@启动报错

  • SpringBoot项 启动后报错,信息如下图:
  • 项目的pom文件
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    <profiles>
    <!-- 开发环境 -->
    <profile>
    <id>dev</id>
    <activation>
    <!--默认激活-->
    <activeByDefault>true</activeByDefault>
    </activation>
    <properties>
    <spring.profiles.active>dev</spring.profiles.active>
    <!-- 环境标识,需要与配置文件的名称相对应 -->
    <!--本地编译时自行修改-->
    <log.homepath>/home/logs</log.homepath>
    </properties>
    </profile>
    <!-- 生产环境 -->
    <profile>
    <id>prod</id>
    <properties>
    <spring.profiles.active>prod</spring.profiles.active>
    </properties>
    </profile>
    </profiles>
  • application.yml配置
    1
    2
    3
    spring:
    profiles:
    active: @spring.profiles.active@
  • 经分析原因,主要是由于此处 @spring.profiles.active@ 值未解析导致,解决方法:
  • pom 中的 build 里面加入 resources 标签内容如下
    1
    2
    3
    4
    <resource>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
    </resource>
  • 添加之后重启项目完美解决报错问题。