springboot怎么禁用缓存
时间: 2023-06-06 09:05:49 浏览: 63
您可以在Spring Boot的配置文件中添加以下代码以禁用缓存:
```
spring.resources.cache.period=0
```
同时,您也可以使用注解的方式来禁用缓存,如下所示:
```
@Cacheable(false)
```
相关问题
springboot禁用浏览器缓存
可以使用以下代码在Spring Boot中禁用浏览器缓存:
```
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**")
.addResourceLocations("classpath:/static/")
.setCachePeriod(0);
}
}
```
这将禁用所有位于``/static``路径下的资源的缓存,确保前端始终获取最新的资源。
Springboot启动时禁用缓存
在 Spring Boot 中,可以通过配置文件来禁用缓存。具体步骤如下:
1. 在 application.properties 文件中添加以下内容:
```
spring.thymeleaf.cache=false
spring.freemarker.cache=false
spring.velocity.cache=false
spring.groovy.template.cache=false
```
2. 在 application.yml 文件中添加以下内容:
```
spring:
thymeleaf:
cache: false
freemarker:
cache: false
velocity:
cache: false
groovy:
template:
cache: false
```
这样就可以禁用 Spring Boot 中常用的模板引擎的缓存了。如果你使用其他的模板引擎,可以查看官方文档来了解如何禁用缓存。