diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupport.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupport.java index 4cd82cf647d..a51af6a215e 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupport.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupport.java @@ -123,8 +123,9 @@ abstract class ScheduledAnnotationReactiveSupport { Publisher publisher = getPublisherFor(method, targetBean); Supplier contextSupplier = () -> new ScheduledTaskObservationContext(targetBean, method); + String displayName = targetBean.getClass().getName() + "." + method.getName(); return new SubscribingRunnable(publisher, shouldBlock, scheduled.scheduler(), - subscriptionTrackerRegistry, observationRegistrySupplier, contextSupplier); + subscriptionTrackerRegistry, displayName, observationRegistrySupplier, contextSupplier); } /** @@ -192,6 +193,8 @@ abstract class ScheduledAnnotationReactiveSupport { final boolean shouldBlock; + final String displayName; + @Nullable private final String qualifier; @@ -202,12 +205,13 @@ abstract class ScheduledAnnotationReactiveSupport { final Supplier contextSupplier; SubscribingRunnable(Publisher publisher, boolean shouldBlock, - @Nullable String qualifier, List subscriptionTrackerRegistry, - Supplier observationRegistrySupplier, - Supplier contextSupplier) { + @Nullable String qualifier, List subscriptionTrackerRegistry, + String displayName, Supplier observationRegistrySupplier, + Supplier contextSupplier) { this.publisher = publisher; this.shouldBlock = shouldBlock; + this.displayName = displayName; this.qualifier = qualifier; this.subscriptionTrackerRegistry = subscriptionTrackerRegistry; this.observationRegistrySupplier = observationRegistrySupplier; @@ -253,6 +257,11 @@ abstract class ScheduledAnnotationReactiveSupport { this.publisher.subscribe(subscriber); } } + + @Override + public String toString() { + return this.displayName; + } } diff --git a/spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupportTests.java b/spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupportTests.java index 3bdf797d8ba..9243a8f80cd 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupportTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -173,6 +173,17 @@ class ScheduledAnnotationReactiveSupportTests { assertThat(p).hasToString("checkpoint(\"@Scheduled 'mono()' in 'org.springframework.scheduling.annotation.ScheduledAnnotationReactiveSupportTests$ReactiveMethods'\")"); } + @Test + void shouldProvideToString() { + ReactiveMethods target = new ReactiveMethods(); + Method m = ReflectionUtils.findMethod(ReactiveMethods.class, "mono"); + Scheduled cron = AnnotationUtils.synthesizeAnnotation(Map.of("cron", "-"), Scheduled.class, null); + List tracker = new ArrayList<>(); + + assertThat(createSubscriptionRunnable(m, target, cron, () -> ObservationRegistry.NOOP, tracker)) + .hasToString("org.springframework.scheduling.annotation.ScheduledAnnotationReactiveSupportTests$ReactiveMethods.mono"); + } + static class ReactiveMethods {