记一次SpringBoot操作redis报错 Error creating bean with name ‘dataSource‘ defined in class path resource解决方法
代码块
以下为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解决方法相关推荐
- 启动springboot报错Error creating bean with name 'dataSource' defined in class path resource
2019独角兽企业重金招聘Python工程师标准>>> 启动springboot报错Error creating bean with name 'dataSource' define ...
- 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 ...
- SpringBoot启动报错: Error creating bean with name ‘“XXXX‘ defined in class path resource
报错信息: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reques ...
- 报错:Error creating bean with name ‘serverEndpointExporter‘ defined in class path resource [group/oneo
背景 启动springboot项目测试类时报错: Error creating bean with name 'serverEndpointExporter' defined in class pat ...
- springboot 启动的时候报错 Error creating bean with name 'solrClient'
springboot 启动的时候报错: org.springframework.beans.factory.BeanCreationException: Error creating bean wit ...
- 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 ...
- 【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 ...
- 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解决方法 文章目录 ...
- 【踩坑日记】springboot项目启动报错error create bean with name
前言 启动springboot项目报错error create bean with name xxx 以为是哪个bean没有装配上,排查了所有的bean,发现都装配了 原因分析 仔细看了报错日志,发现 ...
最新文章
- 打造Worktile敏捷开发管理工具的思与惑
- Android json操作之取得一个对象
- visual assist x太卡了_LeetCode69. x 的平方根
- Tomcat 的类加载机制
- 11月14号站立会议(从即日14号起到24号截至为final阶段工作期)
- 事务嵌套问题_注意Spring事务这一点,避免出现大事务
- 团队项目—第二阶段第三天
- 斗地主AI算法——第七章の被动出牌(1)
- 推荐算法(二)--算法总结
- 2022游戏出海实用发行策略
- 游戏行业如何做防护?游戏被攻击怎么办?
- lowess和loess方法
- linux 搜狗拼音 自动隐藏状态栏
- 百度资源(站长)平台怎么提交收录?
- 【Lombok】@Log | 如何优雅的进行日志记录
- 关于Win10应用商店打不开一直转圈圈的问题
- Chromebook2013 由Fyde os 升级为Deepin v20.2.1 (一)
- 苍穹影视V20七彩视界免sq源码 kyuan源码
- GCC最新版安装及错误解决
- mysql中聚集索引和非聚集索引区别