Search code examples
javaspring-bootgoogle-cloud-platformmigrationgoogle-cloud-pubsub

GCP Spring boot migration 3.x : Required a bean of type 'com.google.cloud.spring.pubsub.core.PubSubTemplate' that could not be found


I've a java 17 application with many modules. I've changed the spring boot version from 2.7.6 to 3.0.6 and I've got the following issues appearing on the module handling PubSubs from GCP

Parameter 1 of method myMessageChannelAdapter in com.controller.file.MyController required a bean of type 'com.google.cloud.spring.pubsub.core.PubSubTemplate' that could not be found.

I've migrated the gcs dependencies as follow :

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>spring-cloud-gcp-dependencies</artifactId>
            <version>4.4.0</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<dependencies>
   ....
<!-- gcs -->
    <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>google-cloud-storage</artifactId>
    </dependency>
    <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>spring-cloud-gcp-pubsub</artifactId>
    </dependency>
    <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>spring-cloud-gcp-core</artifactId>
    </dependency>

Here is how I'm creating my PubSubInboundChannelAdapter :

@Bean
public PubSubInboundChannelAdapter myMessageChannelAdapter(
        @Qualifier("myChannel") MessageChannel inputChannel,
        PubSubTemplate pubSubTemplate) {
   return getInboundAdapter(inputChannel, pubSubTemplate, subscriptionName);
}


@Bean
public MessageChannel myChannel() {
    return new DirectChannel();
}

Should I add another dependency to have a PubSubTemplate automatically autowired or should I create it ? If I have to create it, I can't find a proper way to do it


Solution

  • try to add spring.cloud.gcp.pubsub.project-id properties and update to last spring-cloud-gcp-dependencies 4.5.1 I have solve my migration from springboot 2.7 to 3.1 with pubsub and I didn't created PubSubTemplate, it 's created by spring