代码块

以下为Springboot操作Redis一些简单的测试代码

maven依赖

        <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>

yml配置

spring:redis:host: 127.0.0.1 #redis服务地址port: 6379 #端口password:   #用户名:密码

测试类代码

@SpringBootTest
// @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})class LastApplicationTests<SpringRedisTemplate> {@AutowiredStringRedisTemplate redisTemplate;@Testvoid redisTest () {ValueOperations<String, String> operations = redisTemplate.opsForValue();//向redis中添加一个kv值operations.set("hello","world");//获得hello键的值String hello = operations.get("hello");System.out.println(hello);}
}

看似非常简单没有错误的一个代码块,踩了很大的坑
在使用springboot操作redis进行一个简单的添加k v值时,遇到了一个坑,解决了很久,起初以为是springboot导入依赖版本的问题,切换了版本还不见问题解决。

具体报错详情↓

Error creating bean with name ‘dataSource’ defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method ‘dataSource’ threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourcePropertiesDataSourceBeanCreationException: Failed to determine a suitable driver class

错误详情: 创建名为“dataSource”的bean时,在类路径resource中定义了错误。通过工厂方法实例化Bean失败;嵌套异常是org.springframework.beans。BeanInstantiationException:无法实例化[com.zaxxer.hikari.]HikariDataSource:工厂方法’dataSource’抛出异常

解决方法

在测试启动项加上注解 @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

@EnableAutoConfiguration可以帮助SpringBoot应用将所有符合条件的@Configuration配置都加载到当前SpringBoot创建并使用的IoC容器。

以上为个人所遇到的错误 为不在踩坑问题记录,如帮助到您还请点个赞

记一次SpringBoot操作redis报错 Error creating bean with name ‘dataSource‘ defined in class path resource解决方法相关推荐

  1. 启动springboot报错Error creating bean with name 'dataSource' defined in class path resource

    2019独角兽企业重金招聘Python工程师标准>>> 启动springboot报错Error creating bean with name 'dataSource' define ...

  2. nacos的feign报错Error creating bean with name ‘configurationPropertiesBeans‘ defined in class path reso

    nacos的feign报错Error creating bean with name 'configurationPropertiesBeans' defined in class path reso ...

  3. SpringBoot启动报错: Error creating bean with name ‘“XXXX‘ defined in class path resource

    报错信息: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reques ...

  4. 报错:Error creating bean with name ‘serverEndpointExporter‘ defined in class path resource [group/oneo

    背景 启动springboot项目测试类时报错: Error creating bean with name 'serverEndpointExporter' defined in class pat ...

  5. springboot 启动的时候报错 Error creating bean with name 'solrClient'

    springboot 启动的时候报错: org.springframework.beans.factory.BeanCreationException: Error creating bean wit ...

  6. SpringBoot启动报错Error creating bean with name 'xx': Unsatisfied dependency expressed through field xx

    错误如下: 2020-05-11 08:55:21.333 WARN 937516 --- [ main] ConfigServletWebServerApplicationContext : Exc ...

  7. 【SpringBoot】Error creating bean with name ‘methodValidationPostProcessor‘ defined in class path reso

    报错代码: Correct the classpath of your application so that it contains a single, compatible version of ...

  8. Python pip install 安装包报错ERROR: Could not find a version that satisfies the requirement XXX解决方法

    Python pip install 安装包报错ERROR: Could not find a version that satisfies the requirement XXX解决方法 文章目录 ...

  9. 【踩坑日记】springboot项目启动报错error create bean with name

    前言 启动springboot项目报错error create bean with name xxx 以为是哪个bean没有装配上,排查了所有的bean,发现都装配了 原因分析 仔细看了报错日志,发现 ...

最新文章

  1. 打造Worktile敏捷开发管理工具的思与惑
  2. Android json操作之取得一个对象
  3. visual assist x太卡了_LeetCode69. x 的平方根
  4. Tomcat 的类加载机制
  5. 11月14号站立会议(从即日14号起到24号截至为final阶段工作期)
  6. 事务嵌套问题_注意Spring事务这一点,避免出现大事务
  7. 团队项目—第二阶段第三天
  8. 斗地主AI算法——第七章の被动出牌(1)
  9. 推荐算法(二)--算法总结
  10. 2022游戏出海实用发行策略
  11. 游戏行业如何做防护?游戏被攻击怎么办?
  12. lowess和loess方法
  13. linux 搜狗拼音 自动隐藏状态栏
  14. 百度资源(站长)平台怎么提交收录?
  15. 【Lombok】@Log | 如何优雅的进行日志记录
  16. 关于Win10应用商店打不开一直转圈圈的问题
  17. Chromebook2013 由Fyde os 升级为Deepin v20.2.1 (一)
  18. 苍穹影视V20七彩视界免sq源码 kyuan源码
  19. GCC最新版安装及错误解决
  20. mysql中聚集索引和非聚集索引区别

热门文章

  1. vb.net的循环语句
  2. web前端需要学习什么?这5点很重要
  3. 好莱坞大片的经典画面(搞笑)
  4. Linux查看当前服务器外网IP
  5. 木马病毒的万能查杀方法
  6. 如何实现响应式(自适应)网页
  7. 模拟+贪心 URAL 1804 The Machinegunners in a Playoff
  8. 福利定时关机小工具,定时器,定时关机,定时休眠
  9. 为什么现在会有那么多孩子存在感统失调?
  10. 滴滴第一季度共发生111起治安类案件 83%为乘客侵犯司机