pom.xml中的配置无法被yaml读取

问题描述

项目中指定了多个profiles, 但是application.yaml读取报错,报错信息如下

txt 复制代码
Standard Commons Logging discovery in action with spring-jcl: please remove commons-logging.jar from classpath in order to avoid potential conflicts
12:41:52.325 [main] ERROR org.springframework.boot.SpringApplication -- Application run failed
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 3, column 13:
        active: @env@
                ^

	at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:445)
	at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:238)
	at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingValue.produce(ParserImpl.java:669)
	at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161)
	at org.yaml.snakeyaml.comments.CommentEventsCollector$1.peek(CommentEventsCollector.java:57)
	at org.yaml.snakeyaml.comments.CommentEventsCollector$1.peek(CommentEventsCollector.java:43)

profiles配置如下

xml 复制代码
<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <env>dev</env>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <profile>
        <id>test</id>
        <properties>
            <env>test</env>
        </properties>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <env>prod</env>
        </properties>
    </profile>
</profiles>

application.yaml中的配置

yaml 复制代码
spring:
  profiles:
    active: @env@

无论怎么切换profiles,或者刷新maven项目,一直报这个错误。

之前的项目也使用了这个写法,但是没有这个问题

解决方案

在Maven中添加如下配置

xml 复制代码
<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <!--开启过滤,用指定的参数替换directory下的文件中的参数-->
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

如果继承了spring-boot-parent就不会有这个问题

原因在于,spring-boot-parent中也有这个maven配置,默认将resources下的文件过滤掉,防止maven对文件占位符进行修改

相关推荐
码匠许师傅2 天前
【C++三方组件】TinyXML2:两个文件的极简 XML 解析器
xml·c++
yuzhiboyouye3 天前
my-batisPlus什么时候用xml什么时候用mapper自带的方法,这两种写法专业一点叫什么,什么场景分别使用
xml
筝筝ba4 天前
如何跳过FFDC
xml·linux·运维·服务器·网络
yuzhiboyouye5 天前
那xml对应的sql语法,列举一下
xml·数据库·sql
筝筝ba9 天前
OpenBMC 自动化测试中的多进程陷阱:从 Execute Process 返回异常到 output.xml 损坏问题分析
xml·linux·运维·服务器·网络
spencer_tseng14 天前
[j2cache ehcache.xml]/tmp/.ehcache-diskstore.lock (Permission denied)
xml·linux·python·ehcache·[j2cache
DevOpenClub15 天前
PDF 多格式解析如何避免混用输出:TEXT、HTML、XML 与 TAG 数据契约
xml·前端·数据库·pdf·html
Java小白笔记15 天前
MyBatis XML Mapper 标签与 CRUD 原理实战
xml·数据库·mybatis
风萧萧199916 天前
JAVA :JSONObject转换为XML
xml·java·python
马优晨18 天前
pom.xml 中 jquery webjars 依赖解释
xml·前端·jquery·jquery webjars·webjars依赖