Here is an example of my problem. when no value is supplied to default-name in yml file. @DefaultValue should step in and fill with Name. However, is not how it behaves. An empty string is assigned to defaultName.

application.yml:

account:
  default-name: 

class:

@ConstructorBinding
@ConfigurationProperties(prefix = "account")
public class Account {

    private final String defaultName;

    public Account(@DefaultValue("Name") String defaultName) {
        this.defaultName = defaultName;
    }
..

Comment From: philwebb

The @DefaultValue annotation is only used when there is no property key defined. In your case, the application.yaml file is defining an account.default-name property. We can't really change this behavior as existing application might be provide profile-specific yaml files where they want to replace a value with a blank string.

Comment From: philwebb

I'm wondering if we should look at adding an additional mode attribute to DefaultValue that would allow a different behavior.

Comment From: scottfrederick

Whether or not we change the behavior, we could improve the javadoc for the annotation to make it clear that the default value only applies when no property key is present.

Comment From: hackett91

Thanks for your explanation all. There is no problem here. A good idea to update docs.

Comment From: mbhave

I think improving the javadoc is a good idea. I'm not sure why we would need an additional mode though. If the property is present in the environment, it makes sense that it uses that and not the @DefaultValue. What would be the use case for the property being present but not meant to be used?

Comment From: snicoll

+1 for not having a mode where the default applies if the value is empty.