GoogleCloudPlatform / GoogleCloudPlatform/spring-cloud-gcp

Disabling GCP Pub/Sub fails Application Context startup

Open
#3,889 2 comments 1 reaction 0 assignees View on GitHub
priority: p3 type: bug
Dominant language
Java
Stars
551
Forks
349
Avg merge
1d 13h
Merged PRs (30d)
14

Description

**Describe the bug**

I'm using [Spring Cloud Stream Function Binding](https://googlecloudplatform.github.io/spring-cloud-gcp/6.2.2/reference/html/index.html#binding-with-functions).

```
@Bean
fun foo() = Consumer {
println(it)
}
```

This works, but setting `spring.cloud.gcp.pubsub.enabled` to `false` will fail Application Context startup, if this functional bean is registered in the container:

```
2025-06-17T09:26:52.521+02:00 WARN 51361 --- [spring-cloud-supplier-bug] [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'inputBindingLifecycle'
2025-06-17T09:26:52.524+02:00 INFO 51361 --- [spring-cloud-supplier-bug] [ main] .s.b.a.l.ConditionEvaluationReportLogger :

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2025-06-17T09:26:52.538+02:00 ERROR 51361 --- [spring-cloud-supplier-bug] [ main] o.s.b.d.LoggingFailureAnalysisReporter :

***************************
APPLICATION FAILED TO START
***************************

Description:

A component required a bean of type 'org.springframework.cloud.stream.binder.Binder' that could not be found.

Action:

Consider defining a bean of type 'org.springframework.cloud.stream.binder.Binder' in your configuration.

Process finished with exit code 1
```

This can be worked around by only registering the bean, if Pub/Sub is enabled, but things get nasty, if other library code registers functional beans as well. We are for instance currently introducing [Micrometer's JDBC tracing instrumentation](https://docs.micrometer.io/micrometer/reference/reference/db.html).

[Datasource Micrometer](https://github.com/jdbc-observations/datasource-micrometer)'s Spring Boot auto configuration will registers a `DataSourceProxyConnectionIdManagerProvider` bean, which is a `Supplier`. Spring Cloud Function erroneously wants to bind this bean to a channel as well, leading to above mentioned error, if Pub/Sub is disabled. There's again a workaround by manually including the ConnectionIdManager provider bean in Spring clouds ineligible function definitions,

```
spring.cloud.function.ineligibleDefinitions=observationConnectionIdManagerProvider
```

but this is a) not documented and b) should really be not necessary.

So really two things here IMHO:

* Disabling Pub/Sub should not fail ApplicationContext startup
* Spring Cloud Function should not be so aggressive when trying to bind functions, but this would probably be another feature request/issue

**Versions used**

```
implementation(platform("com.google.cloud:spring-cloud-gcp-dependencies:6.2.2"))
implementation("com.google.cloud:spring-cloud-gcp-pubsub-stream-binder")
```

**Sample**

I've attached a minimal working example and added a `FIXME` comment in `application.yaml`, highlighting the problem.

[spring-cloud-supplier-bug.zip](https://github.com/user-attachments/files/20770831/spring-cloud-supplier-bug.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.