报错如下:
***************************
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).
这个错误的大概意思是:配置DataSource失败,连接数据库的url属性没有指定和没有配置内嵌的数据源
问题原因: Mybatis没有找到合适的加载类,其实是大部分spring - datasource - url没有加载成功,分析原因如下所示.
DataSourceAutoConfiguration会自动加载.
没有配置spring - datasource - url 属性.
spring - datasource - url 配置的地址格式有问题.
配置 spring - datasource - url的文件没有加载.
关于这个问题,我的解决办法是赋值以前对的数据源和修改相关依赖:
为pom.xml文件中添加的依赖:
<!-- jdbc --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <!-- 数据库驱动 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency>
修改配置文件中的属性信息:
server.port=8081 spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/javaee?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT spring.datasource.username=root spring.datasource.password=root mybatis.type-aliases-package=com.simple.test.pojo
在配置这两个文件后,启动项目就没有问题了。
文件参考:
第一个springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde
SpringBoot 2.0 报错: Failed to configure a DataSource: 'url' attribute is not specified and no embe...(这个文件有详细说明原因)
Failed to configure a DataSource: 'url' attribute is not specified and no embedded 的三种解决办法