SpringBoot项目多配置文件运行报错:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-08-19 09:33:28.421 ERROR 15864 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
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).
多配置文件如下:
原因大概率是没有加载到数据库相关的配置文件;
除了常规的检查外,另外可以从两个地方检查:
1、pom文件设置默认配置文件
<profiles>
<profile>
<id>dev</id>
<properties>
<profile-env>dev</profile-env>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<profile-env>test</profile-env>
</properties>
</profile>
</profiles>
其中的
<activation>
<activeByDefault>true</activeByDefault>
</activation>
即表示默认使用“dev”这一配置文件;
2、IDEA设置默认配置文件
如图,在“Edit Configurations”菜单中设置“Active profiles”属性为“dev”即可;