首页 > 其他分享 >@Test下jedisManager.getJedis报错NullPointerException

@Test下jedisManager.getJedis报错NullPointerException

时间:2023-10-11 16:11:07浏览次数:44  
标签:getJedis jedisManager jedis Test Jedis 报错

原文链接:https://www.longkui.site/error/test%e4%b8%8bjedismanager-getjedis%e6%8a%a5%e9%94%99nullpointerexception/4813/

报错代码:

import org.junit.Test;
import redis.clients.jedis.Jedis;


  @Autowired
    private JedisManager jedisManager;

public class TestDemo {

    @Test
    public void test() {
     Jedis jedis = jedisManager.getJedis();
      jedis.set(key,value);
    }
}
上面的代码运行test测试的时候,Jedis jedis = jedisManager.getJedis(); 报错空指针NullPointerException。
后来想到,jedisManager可能要从本地读取配置信息,这种方式在@Test中不能正常使用。于是换个写法

    Jedis jedis = new Jedis("127.0.0.1",6379);
            //jedis.auth("123456"); //设置密码
        jedis.set(key,value);
	jedis.close();

这样就可以在@Test方法下测试jedis了。

 

标签:getJedis,jedisManager,jedis,Test,Jedis,报错
From: https://www.cnblogs.com/longkui-site/p/17757430.html

相关文章

  • c++编译报错解决办法
    所有的警告都被当作是错误在全局域:cc1plus:错误:unrecognizedcommandlineoption‘-Wno-unknown-warning’[-Werror]cc1plus:所有的警告都被当作是错误解决办法:去除CMakeLists.txt中的-Werror......
  • 问题记录贴:vue-i18n在弹出框中$t()报错:TypeError: Cannot read property '_t' of unde
    网上有用的解决方法:vue国际化在弹出框中$t()报错:TypeError:Cannotreadproperty'_t'ofundefined大佬给出的解决方法:弹窗是一个新的Vue对象,只需要单独给弹窗重新绑定i18n即可。代码://dialog/main.jsimportcustomDialogfrom'./dialog.vue'importi18nfrom'@/i18n'......
  • python报错cannot import name ‘compare_ssim‘ from ‘skimage.measure‘
    问题原因: scikit-image版本过高导致 解决办法: 重装,安装低版本 pipuninstallscikit-imagepipinstallscikit-image==0.15.0-U-ihttps://pypi.tuna.tsinghua.edu.cn/simple ......
  • vue3+vite import 引入ThreeBSP库 报错
    我在网上查了一下先用npm下载了三方包npmithree-js-csg再使用constThreeBSP=require('three-js-csg')(THREE)的方法引入出现了这个报错查了是因为require是webpack里的vite不支持所以找不到然后我就尝试使用import的方法引入importThreeBSPfrom'three-js......
  • Atcoder Grand Contest 016 E - Poor Turkeys
    先思考这样一个问题:对于一只火鸡\(i\),我们应该如何判断它最后是否能活下来。如果我们正着判断,我们其实并没有足够的证据表明每一次操作我们应该保留哪只火鸡,也就没法判断最终的答案。但是如果我们倒着考虑,我们发现,如果最后一次操作的两个火鸡都不是\(i\),那么这次操作选啥对答案......
  • 报错Intel MKL FATAL ERROR: Cannot load libmkl_core.so.的一种解决方法
    问题今天上80服务器跑mdistiller的代码时,意外发现torch、numpy都不能用了T_T以torch为例,出现如下报错情况以numpy为例,出现如下报错情况我们先看看报错信息,这个报错来自InterMKL。InterMKL全称是TheIntelMathKernelLibrary,它是一个主要是用于科学计算的共享库,提供了很......
  • Unittest测试框架基础及进阶
    需求假设领导让你开发一个接口测试框架。领导提出了一些新的需求,你如何实现?支持用例优先级、标签,支持通过优先级或标签筛选用例支持用例负责人、迭代,及通过负责人或迭代筛选用例支持多环境配置支持超时及重试机制,防止不稳定用例并发执行用例以提高用例回归效率Unitt......
  • 执行wordcount报错及解决
    今天在执行wordcount词频统计时报错执行语句为hadoopjarshare/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.3.jarwordcountwcinputwcoutput报错如下 这表示指定的输入路径hdfs://hadoop102:8020/user/atguigu/wcinput不存在然后我打开hadoop可视化网页一看确实......
  • Pytest测试框架基础及进阶
    Pytest测试框架基础Pytest测试框架介绍Pytest是Python一款三方测试框架,用于编写和运行单元测试、集成测试和功能测试。Pytest测试框架具有简单、灵活、易于扩展等特点,被广泛应用于Python项目的测试工作中。Pytest主要特点:简单易用:Pytest测试框架的API简单易用,可以快速编写测......
  • powercli报错问题的解决
    报错如图PSC:\Users\admin>Connect-VIServer-Server160.x.x.10-Protocolhttps_userbu\rjkConnect-VIServer:The'Connect-VIServer'commandwasfoundinthemodule'VMware.VimAutomatcouldnotbeloaded.Formoreinformation,run&#......