springmvc--@runwith(springrunner.class)报错

article/2025/9/18 12:07:59

目录

解决方法 

1)代码 这是一个文件上传的测试类 不重要,重要的是 @RunWith(SpringRunner.class)报错! 

import com.github.tobato.fastdfs.domain.StorePath;
import com.github.tobato.fastdfs.domain.ThumbImageConfig;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;@RunWith(SpringRunner.class)
@SpringBootTest
public class FdfsTest {@Autowiredprivate FastFileStorageClient storageClient;@Autowiredprivate ThumbImageConfig thumbImageConfig;@Testpublic void testUpload() throws FileNotFoundException {File file = new File("D:\\壁纸\\白色毛衣 牛仔长裤子 4k美女壁纸_彼岸图网.jpg");// 上传StorePath storePath = this.storageClient.uploadFile(new FileInputStream(file), file.length(), "jpg", null);// 带分组的路径System.out.println(storePath.getFullPath());// 不带分组的路径System.out.println(storePath.getPath());}
}

可以看到在spring-boot-starter-test中已经集成了junit4.12、spring-boot-test ...,所以spring-boot-starter-test 这个依赖很有可能在本地仓库有问题

2)pom.xml文件

<dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><dependency><groupId>com.github.tobato</groupId><artifactId>fastdfs-client</artifactId></dependency></dependencies>

解决方法

  • 方法一: 删除 maven lastUpdated文件  脚本   cleanLastUpdated.bat
@echo off
rem 这是写你的仓库
set REPOSITORY_PATH=F:\program
rem 正在搜索...
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\*lastUpdated*"') do (del /s /q %%i
)
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\aether-*-in-progress"') do (del /s /q %%i
)
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\_remote.repositories"') do (del /s /q %%i
)
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\_maven.repositories"') do (del /s /q %%i
)
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\maven-metadata-nexus*"') do (del /s /q %%i
)
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\resolver-status*"') do (del /s /q %%i
)
rem 搜索完毕
pause

双击运行等着即可

  • 方法二:找到 spring-boot-starter-test 依赖的本地仓库位置,将这个版本删除文件夹删除 如下 将 1.5.15.RELEASE 文件夹删除

        maven仓库\org\springframework\boot(组id)\spring-boot-starter-test(分组)\1.5.15.RELEASE(版本号)

  • 方法三:找一个运行没问题的maven仓库将自己的maven仓库替换掉-->就是改一下settings.xml 仓库位置
  • 方法四:没有运行好的maven仓库,找到本地maven仓库删库整体删除就行了Ctrl+a  删除就行了,重新下载最好用中央私服位置

 

 

 


http://chatgpt.dhexx.cn/article/ootWaLVa.shtml

相关文章

run()和start()方法区别

多线程原理&#xff1a;相当于玩游戏机&#xff0c;只有一个游戏机&#xff08;cpu&#xff09;&#xff0c;可是有很多人要玩&#xff0c;于是&#xff0c;start是排队&#xff01;等CPU选中你就是轮到你&#xff0c;你就run&#xff08;&#xff09;&#xff0c;当CPU的运行的…

关于@RunWith注解的一点问题

问题引入 今天在用IDEA写一个springboot测试的时候&#xff0c;碰到了一个问题。 SpringBootTest public class ServiceTest {Autowiredprivate IUserService userService;Testpublic void testSelectById(){User byId userService.getById(1);System.out.println(byId);} }…

Java学习笔记-@RunWith(SpringRunner.class)

我们在进行Test测试时&#xff0c;除了要保证测试的包和启动包是同一个路径下&#xff0c;并且需要在Test测试类上加上RunWith(SpringRunner.class)注解&#xff0c;否则的话会直接报一个NullPointerExecption的错误&#xff01; RunWith(SpringRunner.class)的作用&#xff1…

@RunWith和 SpringJUnit4ClassRunner ----junit4和Spring一起使用

今天在看Spring的Demo的时候&#xff0c;看到了如此单元测试的写法 如下: RunWIth(SpringJunit4ClassRunner.class) ContextConfiguration(locations {"classpath:applicationContext.xml"} public class MyTest { Test public void hehe() { //....... }…

@RunWith(SpringRunner.class)测试SpringRunner.class爆红

SpringRunner报红无法添加类&#xff0c;上pom.xml文件中去掉scope标签内容即可。如下图所示 然后再点击右边侧面的Reload All Maven Projects即可 方法2 如图所示&#xff0c;直接altenter强制 以上两种方法都不可用的时候&#xff0c;这个时候就得手动导入jar包了&#xf…

Java学习笔记-@RunWith(SpringRunner.class)的作用

建议阅读&#xff1a;https://blog.csdn.net/u011835956/article/details/113950577 注意&#xff1a;Test都是基于Junit写的case&#xff0c;并不是基于TestNg框架&#xff0c;如果是TestNg框架的话&#xff0c;应该要继承AbstractTestNGSpringContextTests&#xff0c;这样b…

SpringBoot在使用测试的时候是否需要@RunWith?

我们在使用SpringBoot进行测试的时候一般是需要加两个注解&#xff1a; SpringBootTest 目的是加载ApplicationContext&#xff0c;启动spring容器。 RunWith 是一个测试启动器&#xff0c;可以加载SpringBoot测试注解让测试在Spring容器环境下执行。如测试类中无此注解&#…

SpringBootTest单元测试—加入@Test无法启动测试方法,什么情况下需要加@RunWith(SpringRunner.class)?

spring环境下单元测试: SpringBoot环境下单元测试: 一、SpringBoot2.4.0之后 二、2.2.0 < SpringBoot < 2.4. 三、SpringBoot2.2.0之前 最近写SpringBootTest单元测试时&#xff0c;加入Test无法启动测试方法&#xff08;我用的是SpringBoot2.2.0之前的版本&#xff09;…

Run Run Run

学习了 2022 年集训队论文 《浅谈与 Lyndon 理论有关的字符串组合问题》 写得很好&#xff0c;像我这样的字符串小白也能看懂 Lyndon 分解 若字符串 w w w 小于它的每一个真后缀&#xff0c;则称 w w w 是 Lyndon 串。若字符串 w w w 是 Lyndon 串&#xff0c;则 w k w ′…

关于springboot在启动测试类时报错的问题和@RunWith的使用

【1】最重要的一点&#xff1a;测试类启动依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupI…

天呐!惊人的Springboot测试.Springboot测试类之@RunWith注解

Springboot测试类之@RunWith注解 Springboot测试类之@RunWith注解Springboot测试类之@RunWith注解 @runWith注解作用: @RunWith就是一个运行器@RunWith(JUnit4.class)就是指用JUnit4来运行@RunWith(SpringJUnit4ClassRunner.class),让测试运行于Spring测试环境,以便在测试开…

SSM中使用测试类RunWith

RunWith(SpringJUnit4ClassRunner.class) 需要使用两个测试包 <!--测试包--><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>5.2.7.RELEASE</version></dependency>…

@RunWith的使用

文章目录 RunWith作用RunWith(SpringJunit4ClassRunner.class) 使用说明测试ActiveProfiles("dev") RunWith作用 RunWith 就是一个运行器 RunWith(JUnit4.class) 就是指用JUnit4来运行 RunWith(SpringJUnit4ClassRunner.class),让测试运行于Spring测试环境 RunWit…

使用命令行创建文件夹和创建文件

进入到指定的目录之后&#xff0c;使用命令&#xff1a;mkdir可以创建新的目录&#xff0c;使用示例&#xff1a; 创建文件&#xff0c;可以使用命令touch&#xff0c;示例&#xff1a;

cmd命令窗口如何创建和删除文件、文件夹,写入内容到文件

首先&#xff0c;同时按住键盘 winR&#xff0c;调出运行窗口&#xff0c;如下图所示&#xff1a; 接下来&#xff0c; &#xff08;1&#xff09;创建文件夹。 使用【 md 文件名 或 mkdir 文件名 】来创建。 完整命令是 md 盘符:\路径\文件夹名&#xff0c;如下图所示&#x…

如何在指定文件夹打开cmd

方法一 1.进入指定的文件夹 &#xff0c;然后选中地址栏&#xff0c;并输入cmd&#xff0c;如下图所示&#xff1a;2.回车&#xff0c;就可以打开对应路径的cmd窗口了&#xff0c;如下图所示&#xff1a; 方法二 1.进入指定的文件夹&#xff0c;按住Shift建鼠标右键&#xff0…

shell、cmd创建文件软连接

&#xff08;一&#xff09;macos shell 一、软链接创建1、创建软链接 ln -s 【目标目录】 【软链接地址】 【目标目录】指软连接指向的目标目录下&#xff0c;【软链接地址】指 “快捷键” 文件名称&#xff0c;该文件是被指令创建的 软链接创建需要同级目录下没有同名的…

windows cmd命令行新建文件,编辑文件,删除文件命令

新建文件 type nul>文件名 编辑文件 copy con 文件名 开始编辑 CTRLz回车保存 删除文件 del 文件名

cmd批量创建文件和文件夹

生成文件夹或者文件 for /l %i in (2,1,10) do md D:\test\新建文件夹%i将上述语句复制到cmd执行即可,如果是批处理要将%i改为%%i,如果是文件&#xff0c;即是 for /l %i in (2,1,10) do cd.> D:\test\新建文件%i.txt学过一点python的应该知道&#xff0c;前面是一个循环语…

cmd命令:批量创建文件夹

for /l %i in (2,1,10) do md D:\test\新建文件夹%i如果是文件&#xff0c;即是 for /l %i in (2,1,10) do cd.> D:\test\新建文件%i.txt学过一点python的应该知道&#xff0c;前面是一个循环语句 &#xff08;2,1,10&#xff09;:编号为2~10&#xff0c;步长为1 md:即make…