找不到 PubSubTemplate、Spring Boot 3、GCP PUB/SUB 的 bean

问题描述 投票:0回答:1

我正在尝试将 GCP pub/sub 与我现有的 Spring Boot 应用程序集成。我在构建中具有所需的依赖项,并提供了使用

subscription config
 中的 
projectID
application.yaml.

连接到 GCP 的配置

但是,PubSubTemplate 尚未在项目中初始化。

Spring Boot版本:3.2

渐变设置:

dependencies {

    implementation "org.springframework.cloud:spring-cloud-gcp-starter-pubsub:1.2.8.RELEASE"
}

ext {
    set('springCloudGcpVersion', "5.1.2")
    set('springCloudVersion', "2023.0.1")
}

dependencyManagement {
    imports {
        mavenBom "com.google.cloud:spring-cloud-gcp-dependencies:${springCloudGcpVersion}"
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
        //mavenBom "org.springframework.cloud:spring-cloud-gcp-starter-pubsub:${springCloudGcpVersion}"
    }
}

application.yaml

spring:
    cloud:
        gcp:
            credentials:
                location: classpath:/1045745-2d4cbe960a5b.json
            project-id: poc-pub-sub
        pubsub:
            enabled: true

代码:

@Configuration
public class Extractor {
@Autowired
  private final PubSubTemplate pubSubTemplate;
}

运行时错误:

com.Extractor 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.

我想 bean 需要由 spring 自动配置,并根据 documentation 使用默认实现。这里是不是少了点什么?

spring-boot google-cloud-pubsub spring-boot-3 spring-cloud-gcp
1个回答
0
投票

更改依赖关系后问题得到解决

来自

dependencies {

    implementation "org.springframework.cloud:spring-cloud-gcp-starter-pubsub:1.2.8.RELEASE"
}

dependencies {

 implementation 'com.google.cloud:spring-cloud-gcp-starter-pubsub'
}
© www.soinside.com 2019 - 2024. All rights reserved.