广告
返回顶部
首页 > 资讯 > 后端开发 > Python >springbootapplication无法使用$获取pom变量的问题及解决
  • 477
分享到

springbootapplication无法使用$获取pom变量的问题及解决

2024-04-02 19:04:59 477人浏览 独家记忆

Python 官方文档:入门教程 => 点击学习

摘要

目录application无法使用$获取pom变量问题如果还想继续使用${}占位符方式或者使用application.yml无法使用@@读取pom.xml中标签值报下面的错误解决办法

application无法使用$获取pom变量问题

Maven的pom文件中进行了多环境变量配置,引用了maven-resources-plugin,在application.properties文件中通过以下配置指定不同环境下的配置文件,

spring.profiles.active = ${profiles.active}

但是${profiles.active}无法从pom文件中获取变量值替换。

由于${}方式会被maven处理。如果你pom继承了spring-boot-starter-parent,Spring Boot已经将maven-resources-plugins默认的${}方式改为了@@方式,如@name@

如果还想继续使用${}占位符方式

只需要在pom文件中加上下面配置即可: 

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <encoding>utf-8</encoding>
                    <useDefaultDelimiters>true</useDefaultDelimiters>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

或者使用

<configuration>
                    <delimiters>
                        <delimiter>@</delimiter>
                    </delimiters>
                    <useDefaultDelimiters>false</useDefaultDelimiters>
                </configuration>

将<useDefaultDelimiters>false</useDefaultDelimiters>

改为<useDefaultDelimiters>true</useDefaultDelimiters>

application.yml无法使用@@读取pom.xml中标签值

在application.yml中使用了@@读取标签值,

报下面的错误

Caused by: 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 5, column 11:         
name: @artifactId@

解决办法

在模块的pom.xml文件下引入一下配置

<build>   
<!--如果不设置resource 会导致application.yml中的@@找不到pom文件中的配置-->    
    <resources>       
        <resource>            
            <directory>src/main/resources</directory>
            <filtering>true</filtering>        
        </resource>    
    </resources>
</build>

然后重新启动,即可成功。

application.yml无法使用@@读取pom.xml中标签值

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。

--结束END--

本文标题: springbootapplication无法使用$获取pom变量的问题及解决

本文链接: https://www.lsjlt.com/news/140555.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作