spring.resources.cache-period 错误

本文介绍了在Spring Boot中配置资源缓存过期时间时遇到的问题及解决方法。主要问题在于配置项名称从spring.resources.cache-period更改为spring.resources.cache.period。文章提供了详细的错误描述和解决步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在springboot 中配置资源缓存过期时间,出错

解决办法

spring.resources.cache-period 改为 spring.resources.cache.period

错误描述如下:


Description:

Binding to target [
Bindable@70a3d3b5 type =
org.springframework.boot.autoconfigure.web.ResourceProperties,
value = ‘provided’,

annotations = array[@org.springframework.boot.context.properties.ConfigurationProperties(
prefix=spring.resources,
value=spring.resources,
ignoreUnknownFields=false,
ignoreInvalidFields=false)]

] failed:

Property: spring.resources.cache-period
Value: 3600
Origin: class path resource [application.properties]:48:32
Reason: The elements [spring.resources.cache-period] were left unbound.

Action:

Update your application’s configuration


看描述属性未绑定上。

查看springboot文档

https://docs.spring.io/spring-boot/docs/2.0.4.RELEASE/reference/htmlsingle/


> spring.resources.cache.period= # Cache period for the resources served by the resource handler. If a duration suffix is not specified, seconds will be used.

在最新的2.0.4 改为 spring.resources.cache.period

spring.resources.cache-period= # Cache period for the resources served by the resource handler, in seconds.

spring.resources.cache-period 已弃用,大概是命名奇怪吧

查看源码
https://github.com/spring-projects/spring-boot/blob/v1.5.4.RELEASE/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java

	public Integer getCachePeriod() {
		return this.cachePeriod;
	}

	public void setCachePeriod(Integer cachePeriod) {
		this.cachePeriod = cachePeriod;
	}

注意有些配置是下划线,有些是 .

spring.resources.add-mappings=true

spring.resources.static-locations

The use of configuration keys that have been renamed was found in the environment: Property source 'applicationConfig: [classpath:/application.yml]': Key: spring.redis.database Line: 18 Replacement: spring.data.redis.database Key: spring.redis.host Line: 16 Replacement: spring.data.redis.host Key: spring.redis.password Line: 19 Replacement: spring.data.redis.password Key: spring.redis.port Line: 17 Replacement: spring.data.redis.port Key: spring.resources.cache.period Line: 33 Replacement: spring.web.resources.cache.period Key: spring.resources.chain.cache Line: 37 Replacement: spring.web.resources.chain.cache Key: spring.resources.chain.gzipped Line: 35 Replacement: spring.web.resources.chain.compressed Property source 'Config resource 'class path resource [application.yml]' via location 'optional:classpath:/'': Key: spring.redis.database Line: 18 Replacement: spring.data.redis.database Key: spring.redis.host Line: 16 Replacement: spring.data.redis.host Key: spring.redis.password Line: 19 Replacement: spring.data.redis.password Key: spring.redis.port Line: 17 Replacement: spring.data.redis.port Key: spring.resources.cache.period Line: 33 Replacement: spring.web.resources.cache.period Key: spring.resources.chain.cache Line: 37 Replacement: spring.web.resources.chain.cache Key: spring.resources.chain.gzipped Line: 35 Replacement: spring.web.resources.chain.compressed Each configuration key has been temporarily mapped to its replacement for your convenience. To silence this warning, please update your configuration to use the new keys. 什么问题
最新发布
08-22
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值