[英]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我为此编写了 spring 启动应用程序以订阅 Google 云 Pub/Sub 主题我使用了 Google 的教程,但是当我运行应用程序时出现此错误
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] osbdLoggingFailureAnalysisReporter: *************************** 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?我怎么解决这个问题?
GcpPubSubAutoConfiguration provides autoconfiguration feature of creating necessary beans including PubSubTemplate. GcpPubSubAutoConfiguration提供了创建必要 bean 的自动配置功能,包括 PubSubTemplate。 In your case, somethng is missed, Kindly ensure that dependencies are in place or recreate following bean to make it work.在您的情况下,遗漏了一些东西,请确保依赖关系到位或重新创建以下 bean 以使其工作。
@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.此外,请确保基于 application.properties 中的以下属性创建GcpContextAutoConfiguration 。
spring.cloud.gcp.credentials.location=${gcp_credentials}
starter dependency :启动器依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-pubsub</artifactId>
</dependency>
Solution解决方案
I added this dependency我添加了这个依赖
implementation 'org.springframework.cloud:spring-cloud-gcp-autoconfigure:1.1.0.RELEASE'
My dependencies我的依赖
dependencies {
implementation 'org.springframework.cloud:spring-cloud-gcp-pubsub:1.1.0.RELEASE'
implementation 'org.springframework.cloud:spring-cloud-gcp-autoconfigure:1.1.0.RELEASE'
implementation "org.springframework.boot:spring-boot-starter-web:2.1.2.RELEASE"
implementation 'org.springframework.integration:spring-integration-core:5.1.2.RELEASE'
}
if using external configuration class that is registering your channels, message handlers etc, make sure to annotate the configuration class with @Import({GcpPubSubAutoConfiguration.class})
如果使用注册频道、消息处理程序等的外部配置类,请确保使用@Import({GcpPubSubAutoConfiguration.class})
注释配置类
@Configuration
@Import({GcpPubSubAutoConfiguration.class})
public class PubSubConfig{
}
I ran into this issue with these versions of spring-boot and spring-cloud-gcp-starter-pub:我在 spring-boot 和 spring-cloud-gcp-starter-pub 的这些版本中遇到了这个问题:
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-pubsub</artifactId>
<version>1.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>1.2.8.RELEASE</version>
</dependency>
and in my application.properties I had spring.cloud.gcp.pubsub.enabled=false
for local development.在我的 application.properties 中,我有spring.cloud.gcp.pubsub.enabled=false
用于本地开发。 I removed spring.cloud.gcp.pubsub.enabled=false
and it worked.我删除spring.cloud.gcp.pubsub.enabled=false
并且它起作用了。 Although now it creates a connection to the pubsub gcp topic, so for local development, you will need to comment out publishing, to avoid sending messages.虽然现在它创建了一个到 pubsub gcp 主题的连接,但是对于本地开发,您需要注释掉 publishing,以避免发送消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.