1.在配置文件配置信息
```
#虚拟文件上传路径
upload-path=F:/tempx/
spring.mvc.static-path-pattern=/**
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,\
classpath:/static/,classpath:/public/,file:${upload-path}
```
2.测试上传文件
文件会被上传至配置的磁盘基本目录
···
@RunWith(SpringRunner.class)
@SpringBootTest(classes = BizApp.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableAutoConfiguration
public class UploadFileTests {
@Value("${upload-path}")
private String uploadPath;
@Test
public void uploadTest() throws Exception {
File f = new File("e:/source.jpg");
FileUtils.copyFile(f, new File(uploadPath+"/myPic.jpg"));
}
}
```
3.访问静态资源
直接在项目中访问 http://[ip]:[port]/[context-path]/myPic.jpg就可以访问到对应的图片