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})

你可能感兴趣的:(SpringBoot报错:Failed to configure a DataSource: 'url' attribute is not specified and no embedded d...)