错误:

Description:

Field jdbcTemplate in com.gwd.dao.impl.IUserDaoImpl required a bean of type 'org.springframework.jdbc.core.JdbcTemplate' that could not be found.
- Bean method 'jdbcTemplate' not loaded because @ConditionalOnSingleCandidate (types: javax.sql.DataSource; SearchStrategy: all) did not find any beans

Action:

Consider revisiting the conditions above or defining a bean of type 'org.springframework.jdbc.core.JdbcTemplate' in your configuration.

解决方案:

在运行类中加入如下代码,DateSource这块看自己的数据源,我这边用的是阿里的druid

    1. package com.gwd;
    2. import javax.sql.DataSource;
    3. import org.springframework.beans.factory.annotation.Autowired;
    4. import org.springframework.boot.SpringApplication;
    5. import org.springframework.boot.autoconfigure.SpringBootApplication;
    6. import org.springframework.context.annotation.Bean;
    7. import org.springframework.core.env.Environment;
    8. import com.alibaba.druid.pool.DruidDataSource;
    9. @SpringBootApplication
    10. public class SpringBootTestApplication {
    11. public static void main(String[] args) {
    12. SpringApplication.run(SpringBootTestApplication.class, args);
    13. }
    14. @Autowired
    15. private Environment env;
    16. //destroy-method="close"的作用是当数据库连接不使用的时候,就把该连接重新放到数据池中,方便下次使用调用.
    17. @Bean(destroyMethod =  "close")
    18. public DataSource dataSource() {
    19. DruidDataSource dataSource = new DruidDataSource();
    20. dataSource.setUrl(env.getProperty("spring.datasource.url"));
    21. dataSource.setUsername(env.getProperty("spring.datasource.username"));//用户名
    22. dataSource.setPassword(env.getProperty("spring.datasource.password"));//密码
    23. dataSource.setDriverClassName(env.getProperty("spring.datasource.driver-class-name"));
    24. dataSource.setInitialSize(2);//初始化时建立物理连接的个数
    25. dataSource.setMaxActive(20);//最大连接池数量
    26. dataSource.setMinIdle(0);//最小连接池数量
    27. dataSource.setMaxWait(60000);//获取连接时最大等待时间,单位毫秒。
    28. dataSource.setValidationQuery("SELECT 1");//用来检测连接是否有效的sql
    29. dataSource.setTestOnBorrow(false);//申请连接时执行validationQuery检测连接是否有效
    30. dataSource.setTestWhileIdle(true);//建议配置为true,不影响性能,并且保证安全性。
    31. dataSource.setPoolPreparedStatements(false);//是否缓存preparedStatement,也就是PSCache
    32. return dataSource;
    33. }
    34. }

解决:No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency的更多相关文章

  1. 解决spring-test中Feign问题: No qualifying bean of type 'org.springframework.cloud.openfeign.FeignContext' available

    问题现象: 启动测试类(含通过Feign远程调用的组件),报错: No qualifying bean of type 'org.springframework.cloud.openfeign.Fei ...

  2. spring异步执行报异常No qualifying bean of type 'org.springframework.core.task.TaskExecutor' available

    最近观察项目运行日志的时候突然发现了一个异常, [2018-04-03 10:49:07] 100.0.1.246 http-nio-8080-exec-9 DEBUG org.springframe ...

  3. SpringBoot- springboot集成Redis出现报错:No qualifying bean of type 'org.springframework.data.redis.connection.RedisConnectionFactory'

    Springboot将accessToke写入Redisk 缓存,springboot集成Redis出现报错 No qualifying bean of type 'org.springframewo ...

  4. 遇到过的问题之“解决 No qualifying bean of type 问题”

    1.问题 解决 No qualifying bean of type 问题 2.思路: 1 检查是否添加了对应注解 2 检查配置是否正确,扫描包名, 类名及id是否正确 一 . 传统SSM项目 ssm ...

  5. NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.web.servlet.view.InternalResourceViewResolver' available

    问题描述: 项目中需要配置多个视图解析器,所以使用ContentNegotiatingViewResolver来处理,在其内部设置了FreeMarkerViewResolver .InternalRe ...

  6. Spring 定时器 No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined

    Spring 定时器 No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined stac ...

  7. Spring 定时器 No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined(转)

    最近项目里面,用了spring的定时任务,一直以来,项目运行的不错.定时器也能正常使用.可是,今天启动项目测试的时候,盯着启动Log看了一阵子,突然间发现,启动的Log中居然有一个异常,虽然一闪而过, ...

  8. spring cloud gateway网关启动报错:No qualifying bean of type 'org.springframework.web.reactive.DispatcherHandler'

    网关配置好后启动报错如下: org.springframework.context.ApplicationContextException: Unable to start web server; n ...

  9. No qualifying bean of type 'org.springframework.scheduling.TaskScheduler' available

    2019-07-22 17:59:30,966 [DEBUG] [localhost-startStop-1] [ScheduledAnnotationBeanPostProcessor.java : ...

随机推荐

  1. 命令行运行python项目文件,报错:ModuleNotFoundError: No module named 'xxxx' 解决办法

    在pycharm中写好了自动化测试脚本,并能在pycharm中正常运行,由于要考虑到无人值守时能自动执行,执行时就需要脱离pycharm,直接能用命令执行.但是直接用命令执行用例文件:python3 ...

  2. django -- 用包来组织数据库模型

    默认情况下一个django app的所有模型都保存在一个叫models.py的文件中.这样事实是不方便管理的: 通过包来组织模型是比较方便的. 一.第一步:删除models.py: rm -rf mo ...

  3. git 权限问题:insufficient permission for adding an object to repository database .git

    在git pull 的时候报错:insufficient permission for adding an object to repository database .git (去仓库里的objec ...

  4. update document in mongodb using java -摘自网络

    update document in mongodb using java: Mongodb driver provides functionality to update document in m ...

  5. java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException 的解决办法之一

    在查看别人的代码的时候,遇到了把工程导入到 Android Studio ,报:ExecutionException: com.android.ide.common.process.ProcessEx ...

  6. 菜鸟教程之工具使用(二)——Maven打包非规范目录结构的Web项目

    用过Maven的人都知道,Maven项目的目录结构跟传统的DynamicWeb项目有些不同.当然我们按照Maven的规范建项目最好,但是当你恰好没有按照Maven的规范来,又恰好需要使用Maven来打 ...

  7. Java 虚拟机类加载器

    虚拟机设计团队把类加载阶段张的”通过一个类的全限定名来获取此类的二进制字节流”这个动作放到Java虚拟机外部去实现,以便让应用程序自己决定如何去获取所需要的类.实现这个动作的代码模块称为”类加载器”. ...

  8. javascript基础拾遗(六)

    1.Date内置对象 获取系统时间 var now = new Date() console.log(now) console.log(now.getDate()) console.log(now.g ...

  9. Lua中的loadfile,dofile,require使用,最后还有调试

    1.loadfile---只编译,不运行. loadfile编译代码成中间码并且返回编译后的chunk作为一个函数,而不执行代码:另外loadfile不会抛出错误信息而是返回错误代号. loadstr ...

  10. Spark SQL inferSchema实现原理探微(Python)【转】

    使用Spark SQL的基础是“注册”(Register)若干表,表的一个重要组成部分就是模式,Spark SQL提供两种选项供用户选择:   (1)applySchema     applySche ...