SpringBoot 配置静态文件缓存

简介: yml配置spring: resources: chain: strategy: content: enabled: true paths: /** cache: true compresse...

yml配置

spring:
  resources:
    chain:
      strategy:
        content:
          enabled: true
          paths: /**
      cache: true
      compressed: false
      enabled: true
    cache:
      cachecontrol:
        cache-public: true

增加代码配置

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.servlet.resource.ResourceUrlProvider;

@ControllerAdvice
public class ControllerConfig {
    @Autowired
    ResourceUrlProvider resourceUrlProvider;

    @ModelAttribute("urls")
    public ResourceUrlProvider urls() {
        return this.resourceUrlProvider;
    }
}

修改静态文件引入fangshi

<link rel="stylesheet" href="${urls.getForLookupPath('/css/index/index.css')}">

不足之处

只能对通过controller进入的页面生效,拦截器直接跳转的页面无效(跳转到页面的URL然后通过controller进入页面是有效的,直接进入页面是无效的)

当前版本

  • Spring Boot 5.1.5.RELEASE
目录
相关文章
|
1月前
|
缓存 NoSQL Java
spring cache整合redis实现springboot项目中的缓存功能
spring cache整合redis实现springboot项目中的缓存功能
45 1
|
1月前
|
缓存 NoSQL Java
【九】springboot整合redis实现启动服务时热点数据保存在全局和缓存
【九】springboot整合redis实现启动服务时热点数据保存在全局和缓存
40 0
|
5月前
|
缓存 NoSQL Java
分布式系列教程(03) -分布式Redis缓存(SpringBoot整合Redis)
分布式系列教程(03) -分布式Redis缓存(SpringBoot整合Redis)
103 0
|
5月前
|
缓存 Java Maven
微服务技术系列教程(07) - SpringBoot - 缓存的使用
微服务技术系列教程(07) - SpringBoot - 缓存的使用
44 0
|
3月前
|
缓存 NoSQL Java
面试官:SpringBoot如何实现缓存预热?
面试官:SpringBoot如何实现缓存预热?
78 0
|
4月前
|
缓存 NoSQL Java
springboot集成图片验证+redis缓存一步到位2
springboot集成图片验证+redis缓存一步到位2
|
4月前
|
缓存 NoSQL Java
springboot集成图片验证+redis缓存一步到位
springboot集成图片验证+redis缓存一步到位
|
4月前
|
缓存 NoSQL Java
SpringBoot - Spring缓存默认配置与运行流程
SpringBoot - Spring缓存默认配置与运行流程
30 1
|
4月前
|
缓存 NoSQL Java
SpringBoot - 缓存入门详解与注解使用实例
SpringBoot - 缓存入门详解与注解使用实例
89 1
|
5月前
|
缓存 NoSQL Java
springboot 启动加载数据库数据到redis缓存
springboot 启动加载数据库数据到redis缓存
141 0