Skip to content

Commit fad610e

Browse files
committed
Add factory for NoopTracer instead of using instance supplier
Closes gh-33298
1 parent 5a3972f commit fad610e

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/actuate/observability/ObservabilityContextCustomizerFactory.java

+17-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.beans.factory.BeanFactory;
2727
import org.springframework.beans.factory.BeanFactoryAware;
2828
import org.springframework.beans.factory.BeanFactoryUtils;
29+
import org.springframework.beans.factory.FactoryBean;
2930
import org.springframework.beans.factory.ListableBeanFactory;
3031
import org.springframework.beans.factory.config.BeanDefinition;
3132
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
@@ -133,7 +134,7 @@ public int hashCode() {
133134
* {@link ConfigurationClassPostProcessor} and adds a {@link Tracer} bean definition
134135
* when a {@link Tracer} hasn't already been registered.
135136
*/
136-
private static class NoopTracerRegistrar implements BeanDefinitionRegistryPostProcessor, Ordered, BeanFactoryAware {
137+
static class NoopTracerRegistrar implements BeanDefinitionRegistryPostProcessor, Ordered, BeanFactoryAware {
137138

138139
private BeanFactory beanFactory;
139140

@@ -154,7 +155,7 @@ public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) t
154155
}
155156
if (BeanFactoryUtils.beanNamesForTypeIncludingAncestors((ListableBeanFactory) this.beanFactory,
156157
Tracer.class, false, false).length == 0) {
157-
registry.registerBeanDefinition("noopTracer", new RootBeanDefinition(Tracer.class, () -> Tracer.NOOP));
158+
registry.registerBeanDefinition("noopTracer", new RootBeanDefinition(NoopTracerFactoryBean.class));
158159
}
159160
}
160161

@@ -164,4 +165,18 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
164165

165166
}
166167

168+
static class NoopTracerFactoryBean implements FactoryBean<Tracer> {
169+
170+
@Override
171+
public Tracer getObject() {
172+
return Tracer.NOOP;
173+
}
174+
175+
@Override
176+
public Class<?> getObjectType() {
177+
return Tracer.class;
178+
}
179+
180+
}
181+
167182
}

0 commit comments

Comments
 (0)