我正在尝试将 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 使用默认实现。这里是不是少了点什么?
更改依赖关系后问题得到解决
来自
dependencies {
implementation "org.springframework.cloud:spring-cloud-gcp-starter-pubsub:1.2.8.RELEASE"
}
到
dependencies {
implementation 'com.google.cloud:spring-cloud-gcp-starter-pubsub'
}