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
发布评论