由于spring Boot是内置tomcat的,所以无法用之前的设置虚拟路径的方式进行设置,spring Boot提供了方便的配置方案,只需要在配置文件中配置就可以.
在application.properties属性文件中配置本地上传文件的路径:
web.img-path=E:/workspace1/temp/ //自定义属性,以/结尾
配置静态资源路径
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,/classpath:/static/,classpath:/public/,file:${web.img-path}
最后访问本地E:/workspace1/temp路径下的文件img.png:
http://localhost:8080/img.png