使用用于 spring boot 应用程序的 json 附加程序进行 GCP 日志记录
我正在尝试添加 gcp 跟踪并记录到 Spring Boot 应用程序,但出现此错误
应用程序无法启动
描述: com.google.cloud.spring.logging.LoggingWebMvcConfigurer 中构造函数的参数 1 需要类型为 com.google.cloud.spring.core.GcpProjectIdProvider 的 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'
,并在 logback-spring.xml 中的 application.properties 中
spring.main.allow-bean-definition-overriding=true
spring.cloud.gcp.logging.enabled=true
spring.sleuth.sampler.probability=1.0
添加了此配置,
<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>
有人遇到类似问题并设法修复它吗?
I am trying adding gcp trace and logging to spring boot app but I get this error
APPLICATION FAILED TO START
Description:
Parameter 1 of constructor in com.google.cloud.spring.logging.LoggingWebMvcConfigurer required a bean of type com.google.cloud.spring.core.GcpProjectIdProvider that could not be found.
Action:
Consider defining a bean of type com.google.cloud.spring.core.GcpProjectIdProvider in your configuration.
in gradle.build, I added the dependencies
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'
and in application.properties
spring.main.allow-bean-definition-overriding=true
spring.cloud.gcp.logging.enabled=true
spring.sleuth.sampler.probability=1.0
in logback-spring.xml I have this configurations
<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>
anyone had similar issue and managed to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些依赖项的版本不一致:
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
。These dependencies' versions are not mutually consistent:
com.google.cloud:spring-cloud-gcp-starter-logging:2.0.0
,org.springframework.cloud:spring-cloud-gcp-autoconfigure:1.1.0.RELEASE
andorg.springframework.cloud:spring-cloud-gcp-starter-trace:1.2.5.RELEASE
.Use the same version for all three dependencies -- the latest is
3.1.0
. Also notice that between 1.x and 2.x+, the group and package names changed tocom.google.cloud
.