我正在尝试将gcp跟踪和日志记录添加到spring-boot应用程序中,但我收到了这个错误
应用程序无法启动
描述:com.google.cloud.spring.logging.LoggingWebMvcConfigurer中构造函数的参数1需要一个类型为com.google.cloud.s普林g.core.GcpProjectIdProvider的bean,但找不到该bean。行动:考虑在配置中定义一个类型为com.google.cloud.spring.core.GcpProjectIdProvider的bean。
在gradle.build中,我添加了依赖项
implementation 'org.springframework.cloud:spring-cloud-gcp-autoconfigure:1.1.0.RELEASE'
implementation 'com.google.cloud:spring-cloud-gcp-starter-logging:2.0.0'
implementation 'org.springframework.cloud:spring-cloud-gcp-starter-trace:1.2.5.RELEASE'
和应用程序属性
spring.main.allow-bean-definition-overriding=true
spring.cloud.gcp.logging.enabled=true
spring.sleuth.sampler.probability=1.0
在logback-spring.xml中,我有以下配置
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<springProfile name="dev |tcm | ver | prd">
<!--include resource="com/google/cloud/spring/logging/logback-json-appender.xml"/-->
<property name="projectId" value="${projectId:-${GOOGLE_CLOUD_PROJECT}}"/>
<appender name="CONSOLE_JSON" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="com.google.cloud.spring.logging.StackdriverJsonLayout">
<!--projectId>${projectId}</projectId-->
<!--<includeTraceId>true</includeTraceId>-->
<!--<includeSpanId>true</includeSpanId>-->
<!--<includeLevel>true</includeLevel>-->
<!--<includeThreadName>true</includeThreadName>-->
<!--<includeMDC>true</includeMDC>-->
<!--<includeLoggerName>true</includeLoggerName>-->
<!--<includeFormattedMessage>true</includeFormattedMessage>-->
<!--<includeExceptionInMessage>true</includeExceptionInMessage>-->
<!--<includeContextName>true</includeContextName>-->
<!--<includeMessage>false</includeMessage>-->
<!--<includeException>false</includeException>-->
<!--<serviceContext>
<service>service-name</service>
<version>service-version</version>
</serviceContext>-->
<!--<customJson>{"custom-key": "custom-value"}</customJson>-->
</layout>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE_JSON"/>
</root>
</springProfile>
</configuration>
有人遇到过类似的问题并设法解决了吗?
这些依赖项的版本不相互一致:com.google.cloud:spring-cloud-gcp-starter-logging:2.0.0
、org.springframework.cloud:spring-cloud-gcp-autoconfigure:1.1.0.RELEASE
和org.springframework.cloud:spring-cloud-gcp-starter-trace:1.2.5.RELEASE
。
对所有三个依赖项使用相同的版本——最新的是3.1.0
。还要注意,在1.x和2.x+之间,组和包的名称已更改为com.google.cloud
。