Skip to content

SpEL Expressions in config does not handle non-string-like values #2989

@Nephery

Description

@Nephery

Describe the issue
When the config has a SpEL expression which looks like a boolean or number (i.e. things that YAML doesn't automatically treat as a string), then applications will fail to startup with:

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

Description:

Failed to bind properties under 'spring.cloud.stream.bindings.<binding-name>.producer.partition-key-expression' to org.springframework.expression.Expression:

    Property: spring.cloud.stream.bindings.producer.partition-key-expression
    Value: "true"
    Origin: class path resource [application.yml] - 84:18
    Reason: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.Boolean] to type [org.springframework.expression.Expression]

To Reproduce
Steps to reproduce the behavior:

  1. Use any config property declared with the type Expression, such as spring.cloud.stream.bindings.<binding-name>.producer.partition-key-expression.
    • Note: I'm using a yaml file for my config when I tested this.
    • Using partition-key-expression here just as a way to illustrate the problem. We're not actually using partition-key-expression to set number or boolean values, but a custom config property declared in the same way.
  2. Set this config property with a boolean-like or number-like value, such as true or 5. e.g.:
spring:
  cloud:
    stream:
      bindings:
        <binding-name>:
          producer:
            partition-key-expression: 5  # must not be quoted in ""
  1. Start app
  2. See error

Version of the framework
Spring boot: 3.3.2
Spring Cloud: 2023.0.3

Expected behavior
All values passed to expression-typed config options should automatically be treated as strings when converting them to Expressions.

My guess is that SpelConverter either needs to be updated to handle boolean and number types, or delegate to the ConversionService to convert any arbitrary value to a String before converting it to an Expression.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions