將上传图片存放到非项目路劲中,没用文件服务器,也没有使用流传送。实现方案是改变spring的默认静态图片资源路径,当然,这并不是完美的方案:可能也会遇到部署的时候,指定的路径中没有静态图片资源会导致页面无法渲染图片、资源没有打包到项目中。上自己的解决过程。
需要配置springboot。
1、配置application.properties文件,添加配置指定上传路径,比如我的配置字段为:cbs.imagesPath=file:/D:/upload/
2、添加配置类:
import org.slf4j.LoggerFactory;
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 WebAppConfig extends WebMvcConfigurerAdapter {
@Value("${cbs.imagesPath}")
private String mImagesPath;
@Override
public void addResourceHandlers(ResourceHand