简体   繁体   English

Google Cloud Pub/Sub API 和 Spring 引导应用程序出现问题

[英]Problem with Google Cloud Pub/Sub API and Spring boot application

I write spring boot application for subscribing Google cloud Pub/Sub topic for this I use Google's tutorial , but when I run application I have get this error我为此编写了 spring 启动应用程序以订阅 Google 云 Pub/Sub 主题我使用了 Google 的教程,但是当我运行应用程序时出现此错误

 2019-02-02 18:03:10.248 INFO 15080 --- [ main] o.apache.catalina.core.StandardService: Stopping service [Tomcat] 2019-02-02 18:03:10.271 INFO 15080 --- [ main] ConditionEvaluationReportLoggingListener: Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2019-02-02 18:03:10.610 ERROR 15080 --- [ main] osbdLoggingFailureAnalysisReporter: *************************** APPLICATION FAILED TO START *************************** Description: Parameter 1 of method messageChannelAdapter in tech.garoon.cloud.CloudApplication required a bean of type 'org.springframework.cloud.gcp.pubsub.core.PubSubTemplate' that could not be found. Action: Consider defining a bean of type 'org.springframework.cloud.gcp.pubsub.core.PubSubTemplate' in your configuration. Process finished with exit code 1

How Can I solve this problem?我怎么解决这个问题?

GcpPubSubAutoConfiguration provides autoconfiguration feature of creating necessary beans including PubSubTemplate. GcpPubSubAutoConfiguration提供了创建必要 bean 的自动配置功能,包括 PubSubTemplate。 In your case, somethng is missed, Kindly ensure that dependencies are in place or recreate following bean to make it work.在您的情况下,遗漏了一些东西,请确保依赖关系到位或重新创建以下 bean 以使其工作。

    @Bean
    public PubSubTemplate pubSubTemplate(PubSubPublisherTemplate pubSubPublisherTemplate,
            PubSubSubscriberTemplate pubSubSubscriberTemplate) {
        return new PubSubTemplate(pubSubPublisherTemplate, pubSubSubscriberTemplate);
    }

Additionally, make sure GcpContextAutoConfiguration is created based on below properties in application.properties.此外,请确保基于 application.properties 中的以下属性创建GcpContextAutoConfiguration

spring.cloud.gcp.credentials.location=${gcp_credentials}

starter dependency :启动器依赖

      <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-gcp-starter-pubsub</artifactId>
        </dependency>

Solution解决方案

I added this dependency我添加了这个依赖

implementation 'org.springframework.cloud:spring-cloud-gcp-autoconfigure:1.1.0.RELEASE'

My dependencies我的依赖

dependencies {
    implementation 'org.springframework.cloud:spring-cloud-gcp-pubsub:1.1.0.RELEASE'
    implementation 'org.springframework.cloud:spring-cloud-gcp-autoconfigure:1.1.0.RELEASE'
    implementation "org.springframework.boot:spring-boot-starter-web:2.1.2.RELEASE"
    implementation 'org.springframework.integration:spring-integration-core:5.1.2.RELEASE'
}

if using external configuration class that is registering your channels, message handlers etc, make sure to annotate the configuration class with @Import({GcpPubSubAutoConfiguration.class})如果使用注册频道、消息处理程序等的外部配置类,请确保使用@Import({GcpPubSubAutoConfiguration.class})注释配置类

@Configuration
@Import({GcpPubSubAutoConfiguration.class})
public class PubSubConfig{

}

I ran into this issue with these versions of spring-boot and spring-cloud-gcp-starter-pub:我在 spring-boot 和 spring-cloud-gcp-starter-pub 的这些版本中遇到了这个问题:

            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-gcp-starter-pubsub</artifactId>
            <version>1.2.8.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>1.2.8.RELEASE</version>
        </dependency>

and in my application.properties I had spring.cloud.gcp.pubsub.enabled=false for local development.在我的 application.properties 中,我有spring.cloud.gcp.pubsub.enabled=false用于本地开发。 I removed spring.cloud.gcp.pubsub.enabled=false and it worked.我删除spring.cloud.gcp.pubsub.enabled=false并且它起作用了。 Although now it creates a connection to the pubsub gcp topic, so for local development, you will need to comment out publishing, to avoid sending messages.虽然现在它创建了一个到 pubsub gcp 主题的连接,但是对于本地开发,您需要注释掉 publishing,以避免发送消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring 引导中的 Pub/Sub 实现 - Pub/Sub Implementation in Spring boot Google Cloud Pub/Sub 按 ID 检索消息 - Google Cloud Pub/Sub retrieve message by ID 用于监控谷歌云发布/订阅的 Stackdriver 延迟 - Stackdriver latency for monitoring google cloud pub/sub Google Cloud Pub/Sub 和多个接收器 - Google Cloud Pub/Sub and multiple receivers 如何谷歌云发布/订阅忽略消息 - how to google cloud pub/sub ignore message 在 spring 启动 2.6.1 中使用 spring-cloud-gcp-pub-sub-stream-binder 时未发现内部方法错误 - internal method not found error while using spring-cloud-gcp-pub-sub-stream-binder in spring boot 2.6.1 为 Google Cloud 中的临时转码器 API 作业请求配置发布/订阅目标 - Configuring Pub/Sub destination for ad-hoc Transcoder API job requests in Google Cloud 通过 configMap 将参数传递给 GKE google cloud 中的 Spring boot 应用程序 - Passing params via configMap to Spring boot application in GKE google cloud R 库将消息发布到 Google Cloud Pub/Sub 主题 - R library to publish a message to Google Cloud Pub/Sub topics 谷歌云发布/订阅 - 订阅者未将消息转发到死信主题 - Google cloud Pub/Sub - subscriber not forwarding messages to dead letter topic
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM