Could not autowire. No beans of ‘DataSource’ type found

初学Springboot整合JDBC的时候报错

在这里插入图片描述

解决方法:

  1. 检查项目结构,主启动类位置是否正确
  2. 把自动装配@Autowired换成@Resource,
    @Autowired是按类型查找Bean,@Resource是按名查找
  3. 可能是缺少依赖,在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>
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐