Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

How Can I solve this problem?

like image 538
Rid Hrant Avatar asked Oct 27 '25 06:10

Rid Hrant


1 Answers

GcpPubSubAutoConfiguration provides autoconfiguration feature of creating necessary beans including PubSubTemplate. In your case, somethng is missed, Kindly ensure that dependencies are in place or recreate following bean to make it work.

    @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.

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

starter dependency:

      <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-gcp-starter-pubsub</artifactId>
        </dependency>
like image 162
Barath Avatar answered Oct 28 '25 19:10

Barath



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!