当前位置: 首页 > 知识库问答 >
问题:

我正在使用apache kafka、Spring cloud sleuth和sleuth otel依赖项,我得到了错误

葛修永
2023-03-14

类路径资源[org/springframework/cloud/sleuth/instrument/web/client/TraceWebClientAutoConfiguration$restemplateconfig$TraceInterceptorConfiguration.class]中定义的bean“traceresttemplatebeanpostsprocessor”,[org/springframework/cloud/sleuth/autoconfig/instrument/web/client/TraceWebClientAutoConfiguration$restemplateconfig$TraceInterceptorConfiguration.class]并禁用覆盖

POM文件中使用的附加sleuth依赖项:


<release.train.version>2020.0.4</release.train.version>
<spring-cloud-sleuth-otel.version>1.0.0-M12</spring-cloud-sleuth-otel.version>
<!-- Spring Cloud Sleuth requires a Spring Cloud BOM -->
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <!-- Provide the latest stable Spring Cloud release train version (e.g. 2020.0.0) -->
            <version>${release.train.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <!-- Spring Cloud Sleuth OTel requires a Spring Cloud Sleuth OTel BOM -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-sleuth-otel-dependencies</artifactId>
            <!-- Provide the version of the Spring Cloud Sleuth OpenTelemetry project -->
            <version>${spring-cloud-sleuth-otel.version}</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>

<!-- You 'll need those to add OTel support -->
<repositories>
    <repository>
        <id>spring-milestones</id>
        <url>https://repo.spring.io/milestone</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-milestones</id>
        <url>https://repo.spring.io/milestone</url>
    </pluginRepository>
</pluginRepositories>

<dependencies>
    <!-- Boot's Web support -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <!-- Sleuth with Brave tracer implementation -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-sleuth</artifactId>
        <exclusions>
            <!-- Exclude Brave (the default) -->
            <exclusion>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-sleuth-brave</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- Add OpenTelemetry tracer -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-sleuth-otel-autoconfigure</artifactId>
    </dependency>
    <dependency>
        <groupId>io.opentelemetry</groupId>
        <artifactId>opentelemetry-exporter-otlp</artifactId>
    </dependency>
    <dependency>
        <groupId>io.opentelemetry</groupId>
        <artifactId>opentelemetry-exporter-otlp-trace</artifactId>
    </dependency>
    <dependency>
        <groupId>io.grpc</groupId>
        <artifactId>grpc-netty-shaded</artifactId>
        <version>1.41.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-sleuth-zipkin</artifactId>
        <version>3.0.3</version>
    </dependency>

</dependencies>

共有1个答案

穆华彩
2023-03-14

默认情况下,Spring Boot 2.1中禁用了bean的重写。您可以尝试添加Spring。主要的在yml中允许bean定义重写=true,或者使用@ComponentScan从SpringBootApplication类中排除父配置。

Example : 

@SpringBootApplication
@ComponentScan(excludeFilters = 
        {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = TraceInterceptorConfiguration.class)})
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}
 类似资料: