Skip to content

RoutingFunctionEnvironmentPostProcessor v4.3.1 throws ClasscastException when spring-cloud-starter-bootstrap is in the classpath #3165

@pgehl

Description

@pgehl

Describe the issue
We upgraded our application to spring-cloud version 2025.0.1 (spring-cloud-stream v4.3.1) from 2025.0.0 (spring-cloud-stream v4.3.0).

Our application fails to start.

The application uses org.springframework.cloud:spring-cloud-starter-bootstrap .

RoutingFunctionEnvironmentPostProcessor throws
java.lang.ClassCastException: class org.springframework.cloud.bootstrap.BootstrapApplicationListener$1 cannot be cast to class org.springframework.core.env.StandardEnvironment

To Reproduce
Steps to reproduce the behavior:

  1. Upgrade spring-cloud to version 2025.0.1
  2. Add org.springframework.cloud:spring-cloud-starter-bootstrap in the classpath
  3. Use org.springframework.cloud:spring-cloud-stream-binder-kafka
  4. See error

Version of the framework
spring-cloud version 2025.0.1

Expected behavior
application should start without exception

Additional context
In version 4.3.0
RoutingFunctionEnvironmentPostProcessor has the following method:

@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
	String name = environment.getProperty("spring.cloud.function.definition");
	if (StringUtils.hasText(name) && (
			name.equals(RoutingFunction.FUNCTION_NAME) ||
			name.contains(RoutingFunction.FUNCTION_NAME + "|") ||
			name.contains("|" + RoutingFunction.FUNCTION_NAME)
		)) {
		((StandardEnvironment) environment).getSystemProperties()
			.putIfAbsent("spring.cloud.function.routing.enabled", "true");
	}
}

(StandardEnvironment) environment casting is only done when environment.getProperty("spring.cloud.function.definition") has text.

In version 4.3.1
RoutingFunctionEnvironmentPostProcessor has the following method:

@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
	String name = environment.getProperty("spring.cloud.function.definition");
	if (StringUtils.hasText(name) && (
			name.equals(RoutingFunction.FUNCTION_NAME) ||
			name.contains(RoutingFunction.FUNCTION_NAME + "|") ||
			name.contains("|" + RoutingFunction.FUNCTION_NAME)
		)) {
		((StandardEnvironment) environment).getSystemProperties()
			.putIfAbsent("spring.cloud.function.routing.enabled", "true");
	}
	// perhaps mpve it to separate class as it doesn't have much to do with RoutingFunction
	((StandardEnvironment) environment).getSystemProperties()
		.putIfAbsent("spring.cloud.function.configuration.default.copy-input-headers", "true");
}

The casting is done even if environment.getProperty("spring.cloud.function.definition") has no text.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions