From 95d292a297145c00f8a6bec2eb35023b1eaa1cb9 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 14 Feb 2024 15:05:15 -0500 Subject: [PATCH] Fix NPE for `RabbitAccessor.observationRegistry` When observation is enabled on component, but no `ObservationRegistry` bean in the application context, we must fall back to the default one `ObservationRegistry.NOOP` **Auto-cherry-pick to `3.0.x`** --- .../amqp/rabbit/connection/RabbitAccessor.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitAccessor.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitAccessor.java index 88d7d9b65b..6c91c630f7 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitAccessor.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 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. @@ -33,6 +33,7 @@ * @author Mark Fisher * @author Dave Syer * @author Gary Russell + * @author Artem Bilan */ public abstract class RabbitAccessor implements InitializingBean { @@ -122,7 +123,7 @@ protected void obtainObservationRegistry(@Nullable ApplicationContext appContext if (appContext != null) { ObjectProvider registry = appContext.getBeanProvider(ObservationRegistry.class); - this.observationRegistry = registry.getIfUnique(); + this.observationRegistry = registry.getIfUnique(() -> this.observationRegistry); } }