diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index db1fac9e3ec..397e77499b1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -1016,7 +1016,7 @@ public class ServerProperties { /** * Time-to-live of the static resource cache. */ - private Duration cacheTtl; + private Duration cacheTtl = Duration.ofSeconds(5); public boolean isAllowCaching() { return this.allowCaching; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizerTests.java index 5b303ba4df1..6f38b367314 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizerTests.java @@ -16,6 +16,7 @@ package org.springframework.boot.autoconfigure.web.embedded; +import java.time.Duration; import java.util.Locale; import java.util.function.Consumer; @@ -314,6 +315,19 @@ class TomcatWebServerFactoryCustomizerTests { assertThat(remoteIpValve.getTrustedProxies()).isEqualTo("proxy1|proxy2"); } + @Test + void resourceCacheMatchesDefault() { + ServerProperties properties = new ServerProperties(); + customizeAndRunServer((server) -> { + Tomcat tomcat = server.getTomcat(); + Context context = (Context) tomcat.getHost().findChildren()[0]; + assertThat(properties.getTomcat().getResource().isAllowCaching()) + .isEqualTo(context.getResources().isCachingAllowed()); + assertThat(properties.getTomcat().getResource().getCacheTtl()) + .isEqualTo(Duration.ofMillis(context.getResources().getCacheTtl())); + }); + } + @Test void customStaticResourceAllowCaching() { bind("server.tomcat.resource.allow-caching=false"); @@ -326,7 +340,7 @@ class TomcatWebServerFactoryCustomizerTests { @Test void customStaticResourceCacheTtl() { - bind("server.tomcat.resource.cache-ttl=10000"); + bind("server.tomcat.resource.cache-ttl=10s"); customizeAndRunServer((server) -> { Tomcat tomcat = server.getTomcat(); Context context = (Context) tomcat.getHost().findChildren()[0];