I have an application that uses Pub/Sub on GCP. Subscribing works without an issue however whenever I add
private final PubSubTemplate pubSubTemplate;
I get get an error that reads
Error creating bean with name 'pubSubTemplate' defined in ut.importer.eventprocessor.EventApplication: Unsatisfied dependency expressed through method 'pubSubTemplate' parameter 0: No qualifying bean of type 'com.google.cloud.spring.pubsub.core.publisher.PubSubPublisherTemplate' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
I know that the pubsubTemplate should come with the dependency but I added the bean anyway thinking it could be clashing with another dependency
@Bean@Primarypublic PubSubTemplate pubSubTemplate(PubSubPublisherTemplate pubSubPublisherTemplate, PubSubSubscriberTemplate pubSubSubscriberTemplate) { return new PubSubTemplate(pubSubPublisherTemplate, pubSubSubscriberTemplate);}
However this did not work, I received the same error.
Then I tried
@Import({GcpPubSubAutoConfiguration.class})
with both imports
import org.springframework.cloud.gcp.autoconfigure.pubsub.GcpPubSubAutoConfiguration;
and
import com.google.cloud.spring.autoconfigure.pubsub.GcpPubSubAutoConfiguration;
And still received the same error.
pom.xml
<spring-cloud.version>2023.0.0</spring-cloud.version><spring-cloud-gcp.version>5.1.0</spring-cloud-gcp.version>
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>com.google.cloud</groupId><artifactId>spring-cloud-gcp-dependencies</artifactId><version>${spring-cloud-gcp.version}</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>org.springframework.integration</groupId><artifactId>spring-integration-core</artifactId></dependency><dependency><groupId>com.google.cloud</groupId><artifactId>spring-cloud-gcp-starter-pubsub</artifactId></dependency>< added spring gcp autoconfig but it had no effect - removed>
import com.google.cloud.spring.pubsub.core.PubSubTemplate;import com.google.cloud.spring.pubsub.core.publisher.PubSubPublisherTemplate;import com.google.cloud.spring.pubsub.core.subscriber.PubSubSubscriberTemplate;
Reading the documentation one of these above solutions should have worked. Has anyone had a similar issue or any suggestions on something else to try?