SpringBoot报错:Failed to configure a DataSource: 'url' attribute is not specified and no embedded d...

SpringBoot集成MyBatis时报了如下错误:


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. 项目中引入了MyBatis的依赖,SpringBoot会根据引入的依赖自动配置项目,如果我们在项目中使用了nacos等配置中心组件的话,数据库配置项就不是明文写在项目配置文件中了,这是需要排除DataSourceAutoConfiguration这个类的自动配置。
    在启动类中添加如下注解:

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容