异常(多环境配置)"/>
Do not use @ for indentation 异常(多环境配置)
pom.xml配置 :
<build><plugins><!-- 打包插件 --><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><!-- maven 打包时跳过测试 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>2.20</version><configuration><skipTests>true</skipTests></configuration></plugin></plugins><resources><resource><directory>src/main/resources</directory><!--开启过滤,用指定的参数替换directory下的文件中的参数--><filtering>true</filtering></resource></resources></build><profiles><profile><!-- 本地开发 --><id>dev</id><activation><activeByDefault>false</activeByDefault></activation><properties><!-- server.port即在bootstrap.yml文件中定义的参数@server.port@ --><server.port>2100</server.port><spring.application.name>budget-boot-dev</spring.application.name><nacos.config.namespace>3e1110da-1111-4cff-96c8-d51212415bdc</nacos.config.namespace><nacos.config.server-addr>192.168.3.131:8848</nacos.config.server-addr></properties></profile><profile><!-- test服务器 --><id>test</id><activation><activeByDefault>false</activeByDefault></activation><properties><server.port>2200</server.port><spring.application.name>budget-boot-test</spring.application.name><nacos.config.namespace>3e1110da-1111-4cff-96c8-d51212415bdc</nacos.config.namespace><nacos.config.server-addr>192.168.3.131:8848</nacos.config.server-addr></properties></profile></profiles>
bootstrap.yml中部分代码示例:
server:port: @server.port@compression:enabled: true
spring:application:name: @spring.application.name@cloud:nacos:discovery:namespace: @nacos.config.namespace@server-addr: @nacos.config.server-addr@username: nacospassword: nacosconfig:namespace: @nacos.config.namespace@server-addr: @nacos.config.server-addr@username: nacospassword: nacosfile-extension: ymlshared-configs:- dev-boot.yml
配置完成后,在右侧的Maven会出现Profiles:
spring cloud 项目,注册中心nacos。
以上是完整配置。
若出现:
Do not use @ for indentation 异常
这需要在 <build></bulid> 中添加以下代码:(可参考上面完整配置)
<resources><resource><directory>src/main/resources</directory><!--开启过滤,用指定的参数替换directory下的文件中的参数--><filtering>true</filtering></resource></resources>
经测试发现,如果执行了maven-clean,在启动项目,一样会报错:Do not use @ for indentation 。
后来查到一个办法:maven-clean-compile, 执行清除、编译,在启动。就没问题。因为编译的时候配置文件里的值会被替换掉,但是这样操作很麻烦。
第二个办法:
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-resources-plugin</artifactId><configuration><!-- 指定过滤的表达式<delimit>@</delimit> : 表示 过滤开头为 @ 结束为 @ 的内容,例如 @project.version@<delimit>${*}</delimit> 表示 过滤${}包裹的内容,例如 ${project.vserion}--><delimiters>@</delimiters><useDefaultDelimiters>false</useDefaultDelimiters></configuration></plugin>
再增加一个插件插件配置,这样就好了。在上面配置的基础上加上此配置
发现以上配置有时候不起作用,然后执行maven-clean继续启动也失败。
最后在pom.xml 点击右键选择maven-Reimport:
再启动,正常
参考:
springboot yml配置文件使用@project.xxxx@ 启动报错Do not use @ for indentation_jyyy1990的博客-CSDN博客
更多推荐
Do not use @ for indentation 异常(多环境配置)
发布评论