1、問題
運行springboot項目,遇到了如下的錯誤
org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token found character '@' 。
這是因為我在pom.xml中配置了
<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
<mysql.host>172.30.254.12</mysql.host>
<mysql.port>3306</mysql.port>
<mysql.user>root</mysql.user>
<mysql.password>123456</mysql.password>
</properties>
**<activation>**
** <activeByDefault>true</activeByDefault>**
** </activation>**
</profile>
</profiles>
然后,我希望在application.yml中通過 %mysql.host% 得到 profile 里邊配置的mysql.host屬性。
但是,當項目啟動之后,就報出了上面的錯誤。
2、解決辦法
從網上搜了一下,確實有人曾經遇到了類似的問題,他文章中講到 maven reimport 一下就可以解決。
可是,在我的案例中真實的情況不是這樣的,真實的原因是 pom的profile中沒有增加activation節點,如上面代碼中的加粗部分所示。當我后來搞清楚了真實原因后,增加了activation節點,問題就得到了徹底的解決。