Skip to content

Commit

Permalink
Add factory for NoopTracer instead of using instance supplier
Browse files Browse the repository at this point in the history
Closes gh-33298
  • Loading branch information
mhalbritter committed Nov 22, 2022
1 parent 5a3972f commit fad610e
Showing 1 changed file with 17 additions and 2 deletions.
Expand Up @@ -26,6 +26,7 @@
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
Expand Down Expand Up @@ -133,7 +134,7 @@ public int hashCode() {
* {@link ConfigurationClassPostProcessor} and adds a {@link Tracer} bean definition
* when a {@link Tracer} hasn't already been registered.
*/
private static class NoopTracerRegistrar implements BeanDefinitionRegistryPostProcessor, Ordered, BeanFactoryAware {
static class NoopTracerRegistrar implements BeanDefinitionRegistryPostProcessor, Ordered, BeanFactoryAware {

private BeanFactory beanFactory;

Expand All @@ -154,7 +155,7 @@ public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) t
}
if (BeanFactoryUtils.beanNamesForTypeIncludingAncestors((ListableBeanFactory) this.beanFactory,
Tracer.class, false, false).length == 0) {
registry.registerBeanDefinition("noopTracer", new RootBeanDefinition(Tracer.class, () -> Tracer.NOOP));
registry.registerBeanDefinition("noopTracer", new RootBeanDefinition(NoopTracerFactoryBean.class));
}
}

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

}

static class NoopTracerFactoryBean implements FactoryBean<Tracer> {

@Override
public Tracer getObject() {
return Tracer.NOOP;
}

@Override
public Class<?> getObjectType() {
return Tracer.class;
}

}

}

0 comments on commit fad610e

Please sign in to comment.