failed to configure a datasource: ‘url‘ attribute is not specified and no em

问题场景

在Spring Boot中整合MySQL、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).

解决方法

报错大概意思是未配置DB url ,可是检查发现,配置连接正常,只是这里的数据源采用苞米豆的多数据源

        <!-- 自带数据库连接池,需要注释掉其他的连接池框架 -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
            <version>2.5.8</version>
        </dependency>

这个插件明确要求需要注释掉其他连接池,为了方便,我关闭了数据源自动装配,主启动类修改如下

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class SpringbootApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootApplication.class, args);
    }
}

现在不报错了

posted @ 2023-11-18 10:23  晓枫的春天  阅读(59)  评论(0编辑  收藏  举报