TWiLight Menu++ 复古游戏整合方案:从安装到个性化的全方位指南

核心内容摘要

Elasticsearch慢查询优化:大数据场景下定位与解决方法
李慕婉-仙逆-造相Z-Turbo模型剪枝优化实战

java+vue基于springboot框架的自习室预约选座管理系统的设计与实现

Spring Boot 静态资源管理详解2026 年视角基于 Spring Boot

xSpring Boot 对静态资源CSS、JS、图片、字体、HTML 等的处理非常友好默认配置已经覆盖了绝大多数场景但自定义需求也很常见。

下面从默认规则 → 自定义映射 → WebJars一条龙讲清楚。

默认静态资源处理规则Spring Boot 自动配置Spring Boot 会自动注册一个ResourceHttpRequestHandler处理所有未被 Controller 匹配的请求通常是 /** 路径。

默认查找顺序classpath 优先级从高到低classpath:/META-INF/resources/classpath:/resources/classpath:/static/classpath:/public/额外特殊规则/webjars/**→ 自动映射到 classpath 中所有 WebJars 的/META-INF/resources/webjars/详见

分常见目录对应示例项目结构src/main/resources/ ├── static/ ← 最常用放 css/js/img │ ├── css/ │ │ └── style.css │ ├── js/ │ └── img/ ├── public/ ← 放 index.html 等欢迎页优先级较低 ├── resources/ ← 较少用 └── META-INF/resources/ ← 第三方 jar 常用访问示例假设应用跑在 http://localhost:8080/css/style.css→ 查找 classpath:/static/css/style.css/img/logo.png→ 查找 classpath:/static/img/logo.png/index.html→ 如果存在 public/index.html 或 static/index.html会作为欢迎页默认 URL 模式/**所有路径都尝试匹配静态资源配置文件方式修改默认路径application.yml / properties# 完全替换默认位置逗号分隔多个spring:web:resources:static-locations:-classpath:/my-static/-file:/opt/extra-files/# 外部目录生产常用# 只改 URL 前缀默认 /** 改成 /assets/**spring:mvc:static-path-pattern:/assets/**注意如果用了static-path-pattern/assets/**那么原来/css/style.css就访问不到了要改成/assets/css/style.css。

自定义静态资源映射最灵活方式当默认位置不够用时比如多模块项目、外部目录、特定前缀、缓存控制推荐实现WebMvcConfigurer。

importorg.springframework.context.annotation.Configuration;importorg.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;importorg.springframework.web.servlet.config.annotation.WebMvcConfigurer;ConfigurationpublicclassWebConfigimplementsWebMvcConfigurer{OverridepublicvoidaddResourceHandlers(ResourceHandlerRegistryregistry){// 自定义路径 /files/** → 映射到 classpath:/upload/registry.addResourceHandler(/files/**).addResourceLocations(classpath:/upload/)// classpath.addResourceLocations(file:/data/app/upload/)// 外部磁盘Linux/Windows 路径.setCachePeriod(

// 缓存 1 小时秒.resourceChain(true);// 开启链式解析可加版本控制等// 额外一个/cdn/** → 外部 CDN 或另一个目录registry.addResourceHandler(/cdn/**).addResourceLocations(file:/opt/cdn-static/);// 如果你想保留默认静态资源可以不覆盖 /**Spring Boot 会自动追加// 但如果你覆盖了 /**记得手动加上默认位置registry.addResourceHandler(/**).addResourceLocations(classpath:/static/,classpath:/public/,classpath:/resources/,classpath:/META-INF/resources/);}}高级玩法加版本控制防缓存.addResourceResolver(newVersionResourceResolver().addContentVersionStrategy(/**))// 根据文件内容 MD5 加版本或使用FixedVersionStrategy固定版本号。

WebJars前端依赖管理神器WebJars 把 npm/bower 等前端库打包成 Maven/Gradle 依赖自动放到 classpath。

默认支持Spring Boot 内置无需额外配置路径/webjars/**映射到所有 classpath 中/META-INF/resources/webjars/xxx/添加依赖示例pom.xml!-- Bootstrap 5 --dependencygroupIdorg.webjars/groupIdartifactIdbootstrap/artifactIdversion

5.

3/version/dependency!-- jQuery --dependencygroupIdorg.webjars/groupIdartifactIdjquery/artifactIdversion

3.

1/version/dependencyHTML 中使用两种方式带版本推荐最高效无需额外依赖linkrelstylesheethref/webjars/bootstrap/

5.

3/dist/css/bootstrap.min.cssscriptsrc/webjars/jquery/

3.

1/jquery.min.js/script不带版本版本无关需要额外依赖!-- 额外加这个依赖 --dependencygroupIdorg.webjars/groupIdartifactIdwebjars-locator-lite/artifactId/dependency!-- 自动解析到最新版本 --linkrelstylesheethref/webjars/bootstrap/dist/css/bootstrap.min.css自定义 WebJars 路径很少需要但可以registry.addResourceHandler(/assets/lib/**).addResourceLocations(classpath:/META-INF/resources/webjars/);

4.

常见问题排查清单2026 年高频问题可能原因解决404 Not Found文件不在默认位置 / 路径拼写错检查 src/main/resources/static/ 或 public/静态资源被 Controller 拦截自定义了 RequestMapping(“/**”)让 Controller 路径更具体或调整 static-path-patternSpring Security 拦截静态资源默认所有请求需认证在 SecurityConfig 中.requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()或.antMatchers(/css/**, /js/**, /webjars/**).permitAll()Thymeleaf 中路径问题用了相对路径用/css/style.css绝对路径开头JAR 打包后找不到放错了目录src/main/webapp 只对 war 有效必须放 resources/static/ 等 classpath 下缓存太久不更新默认有缓存开发时加spring.web.resources.cache.period0或用版本策略

推荐的项目目录结构现代前后端分离风格src/main/resources/ ├── static/ # 自己的 css/js/img/font │ ├── css/ │ ├── js/ │ └── assets/ ├── templates/ # Thymeleaf/FreeMarker └── application.yml

总结一句话默认放 static/ 下直接 /css/xx.css 访问自定义实现 WebMvcConfigurer.addResourceHandlers() 最灵活WebJars/webjars/bootstrap/

x.x/… 零配置引入前端库生产加缓存 CDN 版本控制 外部目录挂载重阳你现在遇到的是哪种场景默认 static 不生效想用 WebJars 引入 Vue/React 组件库需要外部目录 缓存优化Spring Security 静态资源放行问题告诉我具体痛点我给你针对性代码

17c21.cm-17c21.cm最新版v.6.56.92-2265安卓网应用

百度百家号客服电话人工服务

123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123