gpt4 book ai didi

java - 运行集成测试时禁用 Spring Cloud Sleuth?

转载 作者:行者123 更新时间:2023-11-30 02:04:18 30 4
gpt4 key购买 nike

当使用org.springframework.cloud:spring-cloud-gcp-starter-trace:1.0.0.RELEASE并在本地运行我的集成测试时,我收到此错误消息:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stackdriverSender' defined in class path resource [org/springframework/cloud/gcp/autoconfigure/trace/StackdriverTraceAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [zipkin2.reporter.Sender]: Factory method 'stackdriverSender' threw exception; nested exception is java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.

这是完全可以理解的,因为这个环境变量在本地不存在,并且我不想在运行测试时使用 Sleuth/Stackdriver 跟踪。我看过reference documentation但我似乎只能找到有关如何针对特定集成点(例如 RxJava、RestTemplate 等)禁用 Sleuth 的信息。但是如何完全禁用 Sleuth?

我尝试设置 spring.sleuth.enabled=false 但这似乎没有任何区别。

最佳答案

操作方法:使用 Zipkin 禁用 Webflux Sleuth 实现的所有测试

如果您有这些依赖项:

implementation 'org.springframework.cloud:spring-cloud-starter-sleuth'
implementation 'org.springframework.cloud:spring-cloud-sleuth-zipkin'

然后,通过将 application.yml 添加到您的 test/resources 文件夹中,完全禁用 Sleuth/Zipkin 进行集成测试:

spring:
sleuth: # All sleuth features disabled for integration tests
enabled: false
reactor:
enabled: false
web:
enabled: false
async:
enabled: false
client:
template:
enabled: false
zipkin: # All zipkin features disabled for integration tests
enabled: false

关于java - 运行集成测试时禁用 Spring Cloud Sleuth?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51809171/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com