芋道源码 - 配置静态资源匿名访问(图片访问)
一、application.yaml 配置
首先在配置文件中添加静态资源映射:
spring:application:name: yudao-serverprofiles:active: localmvc:static-path-pattern: /pictures/**web:resources:static-locations: file:/data/home/huangjiaqi/agent-saas/agent-saas-api/pictures/
关键配置说明:
-
static-path-pattern
:定义URL访问前缀 -
static-locations
:指定本地文件系统实际存储路径
二、安全配置调整
在 YudaoWebSecurityConfigurerAdapter
类中添加匿名访问权限:
// 1.1 静态资源,可匿名访问
.requestMatchers(HttpMethod.GET, "/*.html", "/*.css", "/*.js", "/pictures/**").permitAll()
三、访问测试
完成配置后,重启服务即可通过以下格式访问图片:
http://服务器IP:端口/pictures/年/月/文件名
示例:
http://192.168.1.24:48080/pictures/2025/06/202506060950488009.jpeg