【报错解决】使用@SpringJunitConfig时报空指针异常

报错描述

具体的报错如下图所示:

我的测试代码如下:

复制代码
import config.StudentConfig;
import controller.StudentController;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

@SpringJUnitConfig(StudentConfig.class)
public class SptingtestTest {
    
    @Autowired
    private StudentController studentController;

    @Test
    public void test(){
        studentController.findAll();
    }

}

解决办法

Test导包导错了,应该导入

复制代码
import org.junit.jupiter.api.Test;

再重新运行就可以成功输出了,如下、


这里是希望能与你一起成长进步的小白,希望以上内容对大家有所帮助~~~

相关推荐
NE_STOP2 天前
springMVC-HTTP消息转换器与文件上传、下载、异常处理
spring
JavaGuide3 天前
Claude Opus 4.6 真的用不起了!我换成了国产 M2.5,实测真香!!
java·spring·ai·claude code
玹外之音3 天前
Spring AI MCP 实战:将你的服务升级为 AI 可调用的智能工具
spring·ai编程
来一斤小鲜肉3 天前
Spring AI入门:第一个AI应用跑起来
spring·ai编程
NE_STOP3 天前
springMVC-常见视图组件与RESTFul编程风格
spring
what丶k4 天前
Spring AI 多模态开发全解析:从入门到企业级落地
后端·spring·ai编程
NE_STOP4 天前
springMVC-获取前端请求的数据与三个作用域
spring
莫寒清4 天前
Spring MVC:@PathVariable 注解详解
java·spring·mvc
-大头.4 天前
从 0 开始理解 Spring 的核心思想 —— IoC 和 DI(1)
spring
莫寒清4 天前
Apache Tika
java·人工智能·spring·apache·知识图谱