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