From 5d80d75051f395c17f6b9367e267d458585b336d Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 31 Aug 2024 12:00:14 +0200 Subject: [PATCH 1/4] Follow symlinks during root path traversal Closes gh-33424 --- .../core/io/support/PathMatchingResourcePatternResolver.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java index 02103245586..2f68ab34297 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java @@ -34,6 +34,7 @@ import java.net.URLClassLoader; import java.net.URLConnection; import java.nio.file.FileSystemNotFoundException; import java.nio.file.FileSystems; +import java.nio.file.FileVisitOption; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; @@ -871,7 +872,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol .formatted(rootPath.toAbsolutePath(), subPattern)); } - try (Stream files = Files.walk(rootPath)) { + try (Stream files = Files.walk(rootPath, FileVisitOption.FOLLOW_LINKS)) { files.filter(isMatchingFile).sorted().map(FileSystemResource::new).forEach(result::add); } catch (Exception ex) { From 1db9faf24838b5df83238e36312e9f721f11fa80 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 31 Aug 2024 12:00:26 +0200 Subject: [PATCH 2/4] Avoid shutdown timeout in case of exception on stop Closes gh-33442 --- .../context/support/DefaultLifecycleProcessor.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java b/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java index 1a81210d588..bd351637b40 100644 --- a/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java @@ -371,6 +371,9 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor if (logger.isWarnEnabled()) { logger.warn("Failed to stop bean '" + beanName + "'", ex); } + if (bean instanceof SmartLifecycle) { + latch.countDown(); + } } } } From ce5869eeb07f02dbbcb46beec064a82b680f72a2 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 31 Aug 2024 12:00:34 +0200 Subject: [PATCH 3/4] Consistent test execution with Locale.UK --- .../method/annotation/MethodValidationTests.java | 10 ++++++++++ .../web/servlet/tags/EvalTagTests.java | 13 ++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MethodValidationTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MethodValidationTests.java index f678629f16d..45be68d4d98 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MethodValidationTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MethodValidationTests.java @@ -20,6 +20,7 @@ import java.lang.reflect.Method; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Set; import java.util.function.Consumer; @@ -29,10 +30,12 @@ import jakarta.validation.Valid; import jakarta.validation.constraints.Size; import jakarta.validation.executable.ExecutableValidator; import jakarta.validation.metadata.BeanDescriptor; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.context.MessageSourceResolvable; +import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.http.MediaType; import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; @@ -92,6 +95,8 @@ class MethodValidationTests { @BeforeEach void setup() throws Exception { + LocaleContextHolder.setDefaultLocale(Locale.UK); + LocalValidatorFactoryBean validatorBean = new LocalValidatorFactoryBean(); validatorBean.afterPropertiesSet(); this.jakartaValidator = new InvocationCountingValidator(validatorBean); @@ -121,6 +126,11 @@ class MethodValidationTests { return handlerAdapter; } + @AfterEach + void reset() { + LocaleContextHolder.setDefaultLocale(null); + } + @Test void modelAttribute() { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/EvalTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/EvalTagTests.java index 400f92abcfa..ad5608f043a 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/EvalTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/EvalTagTests.java @@ -22,14 +22,15 @@ import java.util.Locale; import java.util.Map; import jakarta.servlet.jsp.tagext.Tag; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.env.MapPropertySource; import org.springframework.format.annotation.NumberFormat; import org.springframework.format.annotation.NumberFormat.Style; -import org.springframework.format.number.PercentStyleFormatter; import org.springframework.format.support.FormattingConversionServiceFactoryBean; import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.testfixture.servlet.MockHttpServletResponse; @@ -49,6 +50,8 @@ class EvalTagTests extends AbstractTagTests { @BeforeEach void setup() { + LocaleContextHolder.setDefaultLocale(Locale.UK); + context = createPageContext(); FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean(); factory.afterPropertiesSet(); @@ -58,6 +61,11 @@ class EvalTagTests extends AbstractTagTests { tag.setPageContext(context); } + @AfterEach + void reset() { + LocaleContextHolder.setDefaultLocale(null); + } + @Test void printScopedAttributeResult() throws Exception { @@ -81,13 +89,12 @@ class EvalTagTests extends AbstractTagTests { @Test void printFormattedScopedAttributeResult() throws Exception { - PercentStyleFormatter formatter = new PercentStyleFormatter(); tag.setExpression("bean.formattable"); int action = tag.doStartTag(); assertThat(action).isEqualTo(Tag.EVAL_BODY_INCLUDE); action = tag.doEndTag(); assertThat(action).isEqualTo(Tag.EVAL_PAGE); - assertThat(((MockHttpServletResponse) context.getResponse()).getContentAsString()).isEqualTo(formatter.print(new BigDecimal(".25"), Locale.getDefault())); + assertThat(((MockHttpServletResponse) context.getResponse()).getContentAsString()).isEqualTo("25%"); } @Test From 1f6ab1a0c96c3da5cf57963f6a2bf95197335f16 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 31 Aug 2024 12:00:41 +0200 Subject: [PATCH 4/4] Polishing --- .../scheduling/annotation/Scheduled.java | 42 +++++++++---------- .../web/servlet/function/RouterFunctions.java | 30 +++++++------ 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/Scheduled.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/Scheduled.java index 6d407cf6ce0..ed095677913 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/Scheduled.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/Scheduled.java @@ -126,6 +126,27 @@ public @interface Scheduled { */ String zone() default ""; + /** + * Execute the annotated method with a fixed period between invocations. + *

The time unit is milliseconds by default but can be overridden via + * {@link #timeUnit}. + * @return the period + */ + long fixedRate() default -1; + + /** + * Execute the annotated method with a fixed period between invocations. + *

The time unit is milliseconds by default but can be overridden via + * {@link #timeUnit}. + *

This attribute variant supports Spring-style "${...}" placeholders + * as well as SpEL expressions. + * @return the period as a String value — for example, a placeholder + * or a {@link java.time.Duration#parse java.time.Duration} compliant value + * @since 3.2.2 + * @see #fixedRate() + */ + String fixedRateString() default ""; + /** * Execute the annotated method with a fixed period between the end of the * last invocation and the start of the next. @@ -155,27 +176,6 @@ public @interface Scheduled { */ String fixedDelayString() default ""; - /** - * Execute the annotated method with a fixed period between invocations. - *

The time unit is milliseconds by default but can be overridden via - * {@link #timeUnit}. - * @return the period - */ - long fixedRate() default -1; - - /** - * Execute the annotated method with a fixed period between invocations. - *

The time unit is milliseconds by default but can be overridden via - * {@link #timeUnit}. - *

This attribute variant supports Spring-style "${...}" placeholders - * as well as SpEL expressions. - * @return the period as a String value — for example, a placeholder - * or a {@link java.time.Duration#parse java.time.Duration} compliant value - * @since 3.2.2 - * @see #fixedRate() - */ - String fixedRateString() default ""; - /** * Number of units of time to delay before the first execution of a * {@link #fixedRate} or {@link #fixedDelay} task. diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RouterFunctions.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RouterFunctions.java index 7e8a42004fa..393db856077 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RouterFunctions.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RouterFunctions.java @@ -160,6 +160,7 @@ public abstract class RouterFunctions { */ public static RouterFunction resource(RequestPredicate predicate, Resource resource, BiConsumer headersConsumer) { + return resources(new PredicateResourceLookupFunction(predicate, resource), headersConsumer); } @@ -197,6 +198,7 @@ public abstract class RouterFunctions { */ public static RouterFunction resources(String pattern, Resource location, BiConsumer headersConsumer) { + return resources(resourceLookupFunction(pattern, location), headersConsumer); } @@ -240,7 +242,9 @@ public abstract class RouterFunctions { * @return a router function that routes to resources * @since 6.1 */ - public static RouterFunction resources(Function> lookupFunction, BiConsumer headersConsumer) { + public static RouterFunction resources(Function> lookupFunction, + BiConsumer headersConsumer) { + return new ResourcesRouterFunction(lookupFunction, headersConsumer); } @@ -250,12 +254,12 @@ public abstract class RouterFunctions { * can be used to change the {@code PathPatternParser} properties from the defaults, for instance to change * {@linkplain PathPatternParser#setCaseSensitive(boolean) case sensitivity}. * @param routerFunction the router function to change the parser in - * @param parser the parser to change to. + * @param parser the parser to change to * @param the type of response returned by the handler function * @return the change router function */ - public static RouterFunction changeParser(RouterFunction routerFunction, - PathPatternParser parser) { + public static RouterFunction changeParser( + RouterFunction routerFunction, PathPatternParser parser) { Assert.notNull(routerFunction, "RouterFunction must not be null"); Assert.notNull(parser, "Parser must not be null"); @@ -1151,7 +1155,6 @@ public abstract class RouterFunctions { public void accept(Visitor visitor) { visitor.route(this.predicate, this.handlerFunction); } - } @@ -1173,13 +1176,10 @@ public abstract class RouterFunctions { return this.predicate.nest(serverRequest) .map(nestedRequest -> { if (logger.isTraceEnabled()) { - logger.trace( - String.format( - "Nested predicate \"%s\" matches against \"%s\"", - this.predicate, serverRequest)); + logger.trace(String.format("Nested predicate \"%s\" matches against \"%s\"", + this.predicate, serverRequest)); } - Optional> result = - this.routerFunction.route(nestedRequest); + Optional> result = this.routerFunction.route(nestedRequest); if (result.isPresent() && nestedRequest != serverRequest) { serverRequest.attributes().clear(); serverRequest.attributes().putAll(nestedRequest.attributes()); @@ -1197,7 +1197,6 @@ public abstract class RouterFunctions { this.routerFunction.accept(visitor); visitor.endNested(this.predicate); } - } @@ -1207,11 +1206,11 @@ public abstract class RouterFunctions { private final BiConsumer headersConsumer; - public ResourcesRouterFunction(Function> lookupFunction, BiConsumer headersConsumer) { - Assert.notNull(lookupFunction, "Function must not be null"); - Assert.notNull(headersConsumer, "HeadersConsumer must not be null"); + + Assert.notNull(lookupFunction, "Lookup function must not be null"); + Assert.notNull(headersConsumer, "Headers consumer must not be null"); this.lookupFunction = lookupFunction; this.headersConsumer = headersConsumer; } @@ -1279,5 +1278,4 @@ public abstract class RouterFunctions { } } - }