Could not autowire. No beans of ‘DataSource’ type found
初学Springboot整合JDBC的时候报错
解决方法:
- 检查项目结构,主启动类位置是否正确
- 把自动装配@Autowired换成@Resource,
@Autowired是按类型查找Bean,@Resource是按名查找
- 可能是缺少依赖,在pom.xml文件中添加下面依赖其中之一
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>