项目中指定了多个profiles, 但是application.yaml读取报错,报错信息如下
Standard Commons Logging discovery in action with spring-jcl: please remove commons-logging.jar from classpath in order to avoid potential conflicts
12:41:52.325 [main] ERROR org.springframework.boot.SpringApplication -- Application run failed
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 3, column 13:
active: @env@
^
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:445)
at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:238)
at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingValue.produce(ParserImpl.java:669)
at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161)
at org.yaml.snakeyaml.comments.CommentEventsCollector$1.peek(CommentEventsCollector.java:57)
at org.yaml.snakeyaml.comments.CommentEventsCollector$1.peek(CommentEventsCollector.java:43)
profiles配置如下
<profiles>
<profile>
<id>devid>
<properties>
<env>devenv>
properties>
<activation>
<activeByDefault>trueactiveByDefault>
activation>
profile>
<profile>
<id>testid>
<properties>
<env>testenv>
properties>
profile>
<profile>
<id>prodid>
<properties>
<env>prodenv>
properties>
profile>
profiles>
application.yaml中的配置
spring:
profiles:
active: @env@
无论怎么切换profiles,或者刷新maven项目,一直报这个错误。
之前的项目也使用了这个写法,但是没有这个问题
在Maven中添加如下配置
<build>
<resources>
<resource>
<directory>src/main/resourcesdirectory>
<filtering>truefiltering>
resource>
resources>
build>
如果继承了spring-boot-parent就不会有这个问题
原因在于,spring-boot-parent中也有这个maven配置,默认将resources下的文件过滤掉,防止maven对文件占位符进行修改