SpringBoot中多环境配置Profiles
***************************
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).
-
项目中需要进行多个环境的切换时,比如
-
每个环境环境都有对应的url配置,springboot项目运行时报错就是因为选中的环境dataSources中的url,spring找不到出现了错误,可以实现动态切换选中的配置环境;
1、首先在application.xml文件中配置动态激活Profiles文件
spring:
profiles:
active: "@springboot.active@"
2、在application.yml文件中配置所有需要进行切换的环境,中间使用--分隔
---
spring:
profiles:
active: local
---
spring:
profiles:
active: dev
---
spring:
profiles:
active: uat
---
spring:
profiles:
active: prod
---
spring:
profiles:
active: release
3、在pom文件的<buid></buid>中配置文件路径
<resources>
<resource>
<directory