我为此编写了一个用于启动Google Cloud Pub / Sub主题的spring boot应用程序,我使用了Google的tutorial,但是当我运行应用程序时却遇到了这个错误
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] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
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
我该如何解决这个问题?
答案 0 :(得分:1)
GcpPubSubAutoConfiguration 提供了创建包括PubSubTemplate在内的必要bean的自动配置功能。对于您的情况,错过了某些事情,请确保已建立依赖项或重新创建以下bean以使其起作用。
@Bean
public PubSubTemplate pubSubTemplate(PubSubPublisherTemplate pubSubPublisherTemplate,
PubSubSubscriberTemplate pubSubSubscriberTemplate) {
return new PubSubTemplate(pubSubPublisherTemplate, pubSubSubscriberTemplate);
}
此外,请确保根据application.properties中的以下属性创建 GcpContextAutoConfiguration 。
spring.cloud.gcp.credentials.location=${gcp_credentials}
入门依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-pubsub</artifactId>
</dependency>
答案 1 :(得分:0)
解决方案
我添加了此依赖项
implementation 'org.springframework.cloud:spring-cloud-gcp-autoconfigure:1.1.0.RELEASE'
我的依赖项
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'
}
答案 2 :(得分:0)
如果使用正在注册您的频道,消息处理程序等的外部配置类,请确保使用@Import({GcpPubSubAutoConfiguration.class})
注释该配置类
@Configuration
@Import({GcpPubSubAutoConfiguration.class})
public class PubSubConfig{
}