maven多環境配置如下:
<profiles> <profile> <!--開發環境--> <id>dev</id> <properties> <profileActive>dev</profileActive> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <!--測試環境--> <id>test</id> <properties> <profileActive>test</profileActive> </properties> </profile> <profile> <!--正式環境--> <id>prod</id> <properties> <profileActive>prod</profileActive> </properties> </profile> </profiles>
application.yml使用如下:
spring:
profiles:
active: @profileActive@
報錯如下:
Caused by: 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 19, column 13: active: @profileActive@
解決方案如下:
<!--build節點增加內容--> <resources> <resource> <directory>src/main/resources</directory> <!--開啟過濾,用指定的參數替換directory下的文件中的參數--> <filtering>true</filtering> </resource> </resources>