java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > application.yml使用@@pom文件配置

springboot application.yml使用@@pom文件配置问题

作者:blowDestiny

这篇文章主要介绍了springboot application.yml使用@@pom文件配置问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

springboot application.yml使用@@pom文件配置

这几天搞了一下mongodb到springboot 在配置我使用了yml的配置文件 在引用pom文件配置时需要进行配置才可以使用@@

<build>
        <!-- 使用 @@ application.yml 获取pom文件中的配置  -->
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
</build>

如果没有配置指定resources的话 在使用@@获取pom文件配置的时候就会爆出:

'@' that cannot start any token. (Do not use @ for indentation)

springboot中application.yaml无法使用@@读取pom.xml中标签值的问题

application.yaml文件读取不到pom.xml下的标签值,报

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 7, column 13:
        active: @spring.profiles.active@

解决方法

在模块的pom.xml文件下写入

<build>
    <!--重要 如果不设置resource 会导致application.yaml中的@@找不到pom文件中的配置-->
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <!--重要 如果不设置resource 会导致application.yaml中的@@找不到pom文件中的配置-->
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文