首页 > 其他分享 >springboot单元测试中添加了@Autowired任然报错nullpoint(已解决)

springboot单元测试中添加了@Autowired任然报错nullpoint(已解决)

时间:2023-05-04 16:12:23浏览次数:59  
标签:springboot Autowired 单元测试 报错 解决 任然

 使用了autowired还是报错空指针异常说明就是包没有导入,springboot导包的操作在于启动application类,所以问题就在于没有单元测试时没有启动主类,

解决方法:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = SaTokenDemoApplication.class)
加上如上的注解,@runwith只使用junit4运行单元测试,@springbootTest启动主类导入需要的包,如果还有疑问参考
解决SpringBoot单元测试@Autowired不生效问题

解决SpringBoot单元测试@Autowired不生效问题

标签:springboot,Autowired,单元测试,报错,解决,任然
From: https://www.cnblogs.com/neo-y/p/17371546.html

相关文章

  • linux find命令只输出结果 不输出报错信息
     find/-name"*filename*"2>/dev/null *filename*改成你想要查找的文件即可,模糊查找请加上相应的通配符 转自:https://blog.csdn.net/qq_35544379/article/details/111401707  ......
  • Python报错:Can't connect to HTTPS URL because the SSL module is not available
    参考文章:(32条消息)Can‘tconnecttoHTTPSURLbecausetheSSLmoduleisnotavailable-关于anaconda中的SSL模块错误_anacondahttps报错_Sky_Tree_Delivery的博客-CSDN博客具体操作:将以下文件移动位置D:\Anaconda\Library\bin->D:\Anaconda\DLLs(此处D盘为我自己的安......
  • 报错汇总
    ERROR1799(HY000):Creatingindex'PRIMARY'requiredmorethan'innodb_online_alter_log_max_size'bytesofmodificationlog.Pleasetryagain.该日志文件存储了DDL操作期间对表的insert,update,delete的数据记录临时日志文件每次以innodb_sort_buffer_size为单位进......
  • vCenter报错:Log Disk Exhaustion on 10
    vCenter报错:LogDiskExhaustionon101、问题现象:巡检时发现vCenterServer中,错误显示为:LogDiskExhaustionon10(字面意思是日志磁盘耗尽),VC版本6.7在浏览器输入https://appliance-IP-address-or-FQDN:5480,通过5480端口登录VAMI(vCenterServerApplianceManagementI......
  • Nacos修改权重报错caused: errCode: 500, errMsg: do metadata operation failed ;caus
    今天修改Nacos权重时报错如下:caused:errCode:500, caused:errCode:500,errMsg:dometadataoperationfailed;caused:com.alibaba.nacos.con。解决方案:停掉nacos服务将nacos文件夹下data中的protocol文件夹删除重启nacos服务即可 ......
  • github报错Failed to connect to github.com port 443 after 21313 ms: Couldn't conn
    github报错Failedtoconnecttogithub.comport443after21313ms:Couldn'tconnecttoserver网络连接问题,我开vpn了。github报错Recvfailure:Connectionwasreset该错误通常表示网络连接问题,可能是您的Internet连接出现问题或GitHub服务器上的连接问题。刷新重新登......
  • 从Spring源码分析@Autowired依赖注入实现原理
    在平常项目开发中,使用@Autowired注解进行字段注入很常用,本篇就通过Spring源码,重点分析这种方式实现依赖注入的过程。本篇Spring源码版本为5.1.7.RELEASE。在源码中,关键类是AbstractAutowireCapableBeanFactory,这个类继承AbstractBeanFactory,所以在Spring上下文启动......
  • 关于pandas.ExcelWriter()对象在执行.save()时报错FutureWarning: save is not part o
    有时使用pandas将多份数据,写入到Excel中不同的Sheet,可能会用到pandas.ExcelWriter("xxxx.xlsx")对象这样在结束时,就会对对象进行.save()和close(),当然这也是从大部分网站上看到的使用方法但是笔者在实际使用过程中,按这个过程,遇到报错:FutureWarning:saveisnotpartofthepu......
  • spdlog编译报错:表达式的计算结果不是常数
    VSC2131:表达式的计算结果不是常数;错误代码:intarray[cols];正确写法:int*array=newint[cols];错误原因:创建数组时数组长度是不能用变量的参考:https://blog.csdn.net/qq_39027296/article/details/104936998解决思路,这个问题是constepr导致的,那我们就把其中一部分......
  • idea创建SpringBoot项目报错For artifact {mysql:mysql-connector-java:null:jar}: Th
    Forartifact{mysql:mysql-connector-java:null:jar}:Theversioncannotbeempty.报错如图:pom.xml文件如图:添加版本号:就好了......