错误:
启动错误信息:
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、项目不需要使用 DataSource,但是引用了JPA的数据包,这里需要在启动类上增加:
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }
排除数据源的自动配置类。
2、项目使用了Druid, 这时而又非原生的配置,比如增加了动态数据源支持。这时需要在启动类上增加:
@SpringBootApplication(exclude ={DruidDataSourceAutoConfigure.class} )
排除掉Druid的数据源的自动配置类。
总结:项目引用了数据源配置的starter,但是配置文件又未按照starter里的配置方式配置,这时就会出现上面的问题。解决方式就是要么按照原生配置方式来配置,要么排除掉这个自动配置类。

本文介绍了在项目引用数据源starter但配置不一致时,如何通过排除自动配置类解决启动错误。重点讲解了排除DataSourceAutoConfiguration和DruidDataSourceAutoConfigure的情况,并提到了根据项目需求选择原生配置或排除配置类的重要性。
6021

被折叠的 条评论
为什么被折叠?



