Skip to content

Document that placeholders in @DefaultValue annotations are not resolved #23164

Closed
@hwolf

Description

@hwolf

My application uses @DefaultValue annotation with a SpEl expression as default value. I assumed SpringBoot resolves the expression, but SpringBoot doesn't.

Example:

@SpringBootApplication
@EnableConfigurationProperties(SampleApplication.SampleProperties.class)
public class SampleApplication {
  @ConstructorBinding
  @ConfigurationProperties("sample")
  public static class SampleProperties {
    public SampleProperties(String prop1, @DefaultValue("${sample.prop1}") String prop2) {
      System.out.println("prop1=" + prop1);
      System.out.println("prop2=" + prop2);
    }
  }

  public static void main(String[] args) {
    System.setProperty("sample.prop1", "Hello World");
    SpringApplication.run(SampleApplication.class, args);
  }
}

Actual output:

prop1=Hello World
prop2=${sample.prop1}

Expected output:

prop1=Hello World
prop2=Hello World

It would be nice, if SpEl expressions in the @DefaultValue annotations would be resolved as for other Spring annotations, for example, the@Value annotation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions