【SpringBoot启动异常】解决@profileActive@相关异常问题

一、异常信息

org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token found character '@' that cannot start any token. (Do not use @ for indentation) in 'reader', line 55, column 13: active: @profileActive@ ^ at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:439) at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:248) at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingValue.produce(ParserImpl.java:633) at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:165) at org.yaml.snakeyaml.comments.CommentEventsCollector$1.peek(CommentEventsCollector.java:59) at org.yaml.snakeyaml.comments.CommentEventsCollector$1.peek(CommentEventsCollector.java:45) at org.yaml.snakeyaml.comments.CommentEventsCollector.collectEvents(CommentEventsCollector.java:140) at org.yaml.snakeyaml.comments.CommentEventsCollector.collectEvents(CommentEventsCollector.java:119) at org.yaml.snakeyaml.composer.Composer.composeScalarNode(Composer.java:221) at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:191)

二、问题分析

目前我的项目中application.yml、application-dev.yml、application-sit.yml、application-prod.yml

application.yml中部分信息如下:

# Spring配置
spring:
  # 资源信息
  messages:
    # 国际化资源文件路径
    basename: i18n/messages
  profiles:
    active: @profileActive@
  # 文件上传
  servlet:
    multipart:
      # 单个文件大小
      max-file-size: 10MB
      # 设置总上传的文件大小
      max-request-size: 20MB
  # 服务模块
  devtools:
    restart:
      # 热部署开关
      enabled: true

Pom.xml中配置如下:

<profiles>
    <profile>
        <!--    开发环境      -->
        <id>dev</id>
        <properties>
            <profileActive>dev</profileActive>
        </properties>
        <!--    默认激活的环境       -->
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <profile>
        <!--    测试环境      -->
        <id>sit</id>
        <properties>
            <profileActive>sit</profileActive>
        </properties>
    </profile>
    <profile>
        <!--    生产环境      -->
        <id>prod</id>
        <properties>
            <profileActive>prd</profileActive>
        </properties>
    </profile>
</profiles>

通过上述配置在 profiles. Active已经配置了@profileActive@为何还不生效呢?

在网上查询一番资料,有提示pom中缺少

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
    </resource>
</resources>

于是尝试修改如下:

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>2.5.15</version>
            <configuration>
                <fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>  
            <groupId>org.apache.maven.plugins</groupId>  
            <artifactId>maven-war-plugin</artifactId>  
            <version>3.1.0</version>  
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <warName>${project.artifactId}</warName>
            </configuration>  
       </plugin>  
    </plugins>
    <finalName>${project.artifactId}</finalName>
</build>

Maven clean后,然后启动应用,结果真的启动成功了.

三、解决方案

参考上述配置,在build中增加:

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

疯癫的老码农

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值