Springboot2.1.5 Profile切换
application.yml
spring: profiles: active: @spring.active@
pom.xml
<profiles> <profile> <id>local</id> <properties> <spring.active>local</spring.active> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <id>dev</id> <properties> <spring.active>dev</spring.active> </properties> </profile> </profiles>
然后启动报错:
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 17, column 13: active: @spring.active@
如果我加
"@spring.active@"
那么依旧报错为:
*************************** APPLICATION FAILED TO START *************************** Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver class Action: Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active). Disconnected from the target VM, address: '127.0.0.1:58740', transport: 'socket' Process finished with exit code 0
有分析到位的么?如果我直接用 local或者dev 代替@spring.active@就没事。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我试过这个了,也是不行的,所有的配置我都加上了,不行,但是我重新弄了一个新的springboot项目,就可以,不知道哪里出现问题了
yml 中使用单引号 '@spring.active@'
如果parent是spring-boot-parent就不需要上述配置了
勾选maven dev profile,application-dev.yml 会覆盖application.yml
我试过这个了,也是不行的,所有的配置我都加上了,不行,但是我重新弄了一个新的springboot项目,就可以,不知道哪里出现问题了
还差点配置