-
Notifications
You must be signed in to change notification settings - Fork 37.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spring 6.1, NPE for anonymous objects with @Scheduler annotation #31980
Comments
Update, ok I've seen you have already corrected this behaviour protected KeyValue codeNamespace(ScheduledTaskObservationContext context) {
if (context.getTargetClass().getCanonicalName() != null) {
return KeyValue.of(LowCardinalityKeyNames.CODE_NAMESPACE, context.getTargetClass().getCanonicalName());
}
return CODE_NAMESPACE_ANONYMOUS;
} Closing the issue. |
As you've found out, this is a duplicate of #31918, which is already solved in 6.1.3-SNAPSHOT.
I think you can disable this with an observation predicate in the meantime: import io.micrometer.observation.ObservationPredicate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
public class ObservationConfig {
@Bean
public ObservationPredicate disableScheduledObservation() {
return (name, context) -> "tasks.scheduled.execution".equals(name);
}
} Care to elaborate about the changes in your codebase? Usually minor Spring Framework releases come with new features and few deprecations and required code changes. I'd be curious to know which Framework changes caused pain. Now about this particular change, this is a bug in a new feature that was not caught during the milestone phase. |
@bclozel as we didn't know how to disable this, our first approach was to create normal classes so the Thank you for your time. |
Affects: 6.1
Context: Upgrading from Spring Boot 3.1 (Spring 6.0) to Spring Boot 3.2 (Spring 6.1)
We encountered an issue with Beans defined as anonymous objects containing a single method annotated with
@Scheduled
. For instance:Upon execution, these tasks failed to initialize, resulting in the following stack trace:
After investigating and debugging, we found that in this Spring version...
Our issue arises because micrometer
SimpleObservation.start
requires the classcanonicalName
, which returnsnull
for our anonymous objects.We resolved this by using named classes. However, I want to highlight this case as in our case a
MINOR
update has meant a lot of changes in our code base, and there does not seem to be a way to disable this, now default, behaviour in Spring 6.1.Looking forward to your feedback.
The text was updated successfully, but these errors were encountered: