Springboot accesses pictures in other directories outside the project through url

1. First add configuration in the application.properties file:

#资源绝对路径为file:D://sws/module-base/module-base/upload,图片存放的真实路径
#意思是springboot开放此资源路径供外部读取
spring.resources.static-locations=file:D://sws/module-base/module-base/upload
        
#资源映射路径为/image/**,使用url访问的请求路径
spring.mvc.static-path-pattern=/image/**

2. If the project uses authorization authentication, you need to add /image/** to the authentication-free configuration before you can directly access it. 

So you can access the picture: https://localhost:8050/image/731f594961834b4baed6057c68dd6cd1.jpg

 

 

Guess you like

Origin blog.csdn.net/weixin_38959210/article/details/107619844