1

I'm upgrading spring-boot to 2.6.2 and spring-cloud to 2021.0.0, and after upgrading, the brave.Tracer was not able to autowired in a @Configuration class.

The Tracer is autowired as parameter with @Bean component.

I have tried solutions in this question but doesn't work.

here is the @Configuration class:

@Configuration
@ConditionalOnWebApplication
@AutoConfigureAfter(CommonsAutoConfig.class)
@EnableConfigurationProperties({CorsConfig.class, TracingConfiguration.class})
public class WebCommonsAutoConfig
{
    ......
    @Bean(name = "httpRestRequestResponseLogger")
    @RefreshScope
    public FilterRegistrationBean httpRestRequestResponseLogger(
            RequestResponseLogger requestResponseLogger, 
            HeaderAccessor headerAccessor,
            Tracer tracer, 
            HeaderExtractor<HttpServletRequestLoggingWrapper> httpHeaderExtractor)
    {
        final HttpLogFilter httpLogFilter=  new HttpLogFilter(requestResponseLogger, 
                   headerAccessor, tracer, httpHeaderExtractor);
        final FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(httpLogFilter);
        registrationBean.setDispatcherTypes(ASYNC, ERROR, FORWARD, INCLUDE, REQUEST);
        registrationBean.setOrder(HttpLogFilter.ORDER);
        return registrationBean;
    }
    ....
}

With the following error log:

...
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error 
creating bean with name 'scopedTarget.httpRestRequestResponseLogger' defined in class 
path resource [com/vzt/WebCommonsAutoConfig.class]: Unsatisfied dependency expressed 
through method 'httpRestRequestResponseLogger' parameter 2; 
...
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No 
qualifying bean of type 'brave.Tracer' available: expected at least 1 bean which 
qualifies as autowire candidate. Dependency annotations: {}
 

So what shall I do to make the brave.Tracer autowired in this @Configuration class?

Ang Li
  • 11
  • 2
  • 1
    It's solved. This problem is caused by a version mismatching of io.zipkin.brave and spring-boot. After spring cloud 2020, brave is added to spring framework so we can directly use spring-cloud-starter-sleuth for brave.Tracer. – Ang Li Feb 09 '22 at 22:47

1 Answers1

0

Most likely you need to add @AutoConfigureAfter(BraveAutoConfiguration.class). I understand that spring cloud sleuth is on the classpath?

Marcin Grzejszczak
  • 10,624
  • 1
  • 16
  • 32