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

目录

解决方法 

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 {

    @Autowired
    private FastFileStorageClient storageClient;

    @Autowired
    private ThumbImageConfig thumbImageConfig;

    @Test
    public 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  删除就行了,重新下载最好用中央私服位置

 

 

 

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值