Spring boot 启动报:Do not use @ for indentation

编程入门 行业动态 更新时间:2024-10-28 01:14:38

<a href=https://www.elefans.com/category/jswz/34/1769862.html style=Spring boot 启动报:Do not use @ for indentation"/>

Spring boot 启动报:Do not use @ for indentation

这个问题的产生是因为在使用idea 的maven 进行编译的时候,没有将其视为变量,而是作为字符串进行的编译,导致target 中的application.yml 文件中的active 的值为:@activatedProperties@,如下所示:

正常情况下,当maven 进行编译时,会将yml 文件中的多环境配置变量更换为指定的配置值,例如:我的默认配置值是dev 则上图中的yml 文件中的@activatedProperties@将在编译后变为dev,如下所示:

而产生这个问题的原因就是打包后的@activatedProperties@没有变为dev(可通过target/classes/application.yml 查看@activatedProperties@是否变为了dev,idea或maven 打包后会生成一个target 文件),还是和第一张图片一样,而spring boot 无法识别@ 标志导致报错,我的多环境配置是这样的:

<profiles><profile><id>dev</id><properties><activatedProperties>dev</activatedProperties><nacosNamespace></nacosNamespace><gatewayip>localhost</gatewayip></properties><activation><!-- 默认环境 --><activeByDefault>true</activeByDefault></activation></profile><profile><id>test</id><properties><!-- 环境标识,需要与配置文件的名称相对应 --><activatedProperties>test</activatedProperties><nacosNamespace></nacosNamespace><gatewayip>122.114.79.36</gatewayip></properties></profile><profile><id>prod</id><properties><activatedProperties>prod</activatedProperties><nacosNamespace></nacosNamespace></properties></profile></profiles>

最后打包后却仍如下所示:

spring:application:# 服务名name: service-nameprofiles:active:  @activatedProperties@

之后我使用clean 清除target 后重新打包发现,@activatedProperties@变成了dev,之后正常启动

2023年7月27日 补充

如果使用的是idea 启动是需要勾选idea 中maven 中Profiles选项中一项的

 


 

更多推荐

Spring boot 启动报:Do not use @ for indentation

本文发布于:2024-02-16 22:17:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1691636.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Spring   boot   indentation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!