【问题标题】:Problem with Google Cloud Pub/Sub API and Spring boot applicationGoogle Cloud Pub/Sub API 和 Spring Boot 应用程序存在问题
【发布时间】:2019-06-26 21:15:21
【问题描述】:

我为此编写了用于订阅 Google Cloud Pub/Sub 主题的 Spring Boot 应用程序,我使用 Google 的 tutorial,但是当我运行应用程序时出现此错误

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] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
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

我该如何解决这个问题?

【问题讨论】:

    标签: spring spring-boot google-cloud-platform google-cloud-pubsub


    【解决方案1】:

    GcpPubSubAutoConfiguration 提供自动配置功能来创建必要的 bean,包括 PubSubTemplate。在您的情况下,遗漏了一些东西,请确保依赖项到位或重新创建以下 bean 以使其工作。

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

    此外,请确保 GcpContextAutoConfiguration 是根据 application.properties 中的以下属性创建的。

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

    入门依赖

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

    【讨论】:

    • 感谢您的回答我错过了添加一个依赖项。 )) implementation 'org.springframework.cloud:spring-cloud-gcp-autoconfigure:1.1.0.RELEASE'
    • 它是 gcp-starter-pubsub 的一部分。如果以上回答对您有帮助,请采纳。
    • 。我有所有的依赖项。我什至可以导入 GcpPubSubAutoConfiguration。还是不行。仍然得到 No qualifying bean of type 'org.springframework.cloud.gcp.pubsub.core.PubSubTemplate' available.
    【解决方案2】:

    解决方案

    我添加了这个依赖

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

    我的依赖

    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'
    }
    

    【讨论】:

      【解决方案3】:

      如果使用注册频道、消息处理程序等的外部配置类,请确保使用 @Import({GcpPubSubAutoConfiguration.class}) 注释配置类

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

      【讨论】:

        猜你喜欢
        • 2022-01-13
        • 2019-07-07
        • 2019-10-12
        • 2018-08-09
        • 2016-12-16
        • 2021-12-12
        • 1970-01-01
        • 1970-01-01
        • 2020-01-17
        相关资源
        最近更新 更多