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 { } } - }