在Spring Sleuth中,出现了“bean 'spring.sleuth.baggage-keys' already defined”的错误是由于同一个应用程序中存在多个Sleuth存根,因此无法创建Sleuth Baggage Bean所致。下面是可能导致出现此问题的示例代码:
org.springframework.cloud
spring-cloud-starter-sleuth
解决此问题的最佳方法是使用spring-cloud-starter-sleuth-zipkin替换spring-cloud-starter-sleuth。
org.springframework.cloud
spring-cloud-starter-sleuth-zipkin
此外,您还可以通过在application.properties或application.yml文件中显式设置sleuth.baggage-keys属性来解决此问题。
spring:
sleuth:
baggage-keys: your-custom-baggage-key
通过'your-custom-baggage-key”替换为您要使用的自定义Baggage Key,此方法允许您配置Sleuth来创建特定于应用程序的Bean,并使其在应用程序的整个生命周期内一致可用。