<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
如上是我在配置文件中正确配置datasource,并且spring bean管理配置正确情况下仍不能装配DataSource的一个最终解决方法;
具体报错信息:
Field dataSource in *.leaf.util.db.DBManager required a bean of type 'javax.sql.DataSource' that could not be found.
- Bean method 'dataSource' not loaded because @ConditionalOnClass did not find required class 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType'
- Bean method 'dataSource' not loaded because @ConditionalOnClass did not find required classes 'javax.transaction.TransactionManager', 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType'
DataSource是接口,提供了和DriverManager类似的功能,但其抽象层次比DriverManager高,简单来说,可以理解为DataSource是DriverManager的进一步封装,从不关心某一数据库操作的具体实现抽象为了不关心到底是哪一数据库在提供服务。