springBoot 启动之后,代理一个目录,然后就可以通过浏览器url的方式访问这个资源
在 application.proerties中指定一目录
tmp.filePath=file:D:/files/tmp/
2.写一个configuration
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class FilePathConfiguration extends WebMvcConfigurerAdapter {
@Value("${tmp.filePath}")
private String tmpFilePath;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/upload/**").addResourceLocations(tmpFilePath);
super.addResourceHandlers(registry);
}
}
3.在指定的目录存放一个文件
4.访问文件
http://localhost:696/upload/1.txt
评论 (0)