共计 1749 个字符,预计需要花费 5 分钟才能阅读完成。
Failed to determine a suitable driver class
启动就报这个谬误:
Description:
Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-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)
看字面意思是没找到数据源。网上说是在利用中没有用到数据源然而增加了 mybatis 的依赖:
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
很惋惜我不是这种状况,我的这个模块是服务模块,外面用到 mybatis-plus 的相干包,而且 application.yml 文件中也配置了数据源失常:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql://localhost:3306/seckill?serverTimezone=GMT%2B8
说什么要在启动类下面排除数据源的主动注入:
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)// 去掉数据源
而后就报这个错:
Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
而后竟然让写一个根底 dao:
可能是为了解决多数据源的问题吧,勾销了主动注入。没用到多数据源,不太关怀这个。
解决方案:因为咱们 dao 层是继承于一个 dao 基类,所以只有在这个基类中注入任意一个属性即可。SqlSessionFactory 在 spring 配置文件中曾经配置。
public class CommonDao extends SqlSessionDaoSupport {
@Resource
public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory){super.setSqlSessionFactory(sqlSessionFactory);
}
}
而后我所有的 mapper 都要继承这个。。。
果决放弃,最终找到如下计划。
解决办法
亲测无效,在 pom.xml 文件增加如下:
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.yml</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.yml</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
正文完