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 classAction: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>