0

I have following block in application.yaml file:

foo:
  bar: bazz

I want to map that configuration to a configuration class using @ConfigurationProperties.

@Validated
@Getter @Setter
@ConfigurationProperties(prefix = "foo")
public class FooProperties {
    @NotNull
    private String bar;
}

And here is configuration class

@Configuration
@EnableConfigurationProperties(FooProperties.class)
public class FooConfiguration {
    @Bean
    public Foo getFoo(FooProperties properties) {
        ///
    }
}

However when I try to start application I get following error:

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

Description:

Binding to target org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'foo' to a.b.c.FooProperties failed:

    Property: foo.bar
    Value: null
    Reason: must not be null


Action:

Update your application's configuration

Did I miss anything else? I cant figure out why such a trivial thing fails.

  • The extension of application.yaml is '.yml'. I hope you have provided that correctly.Also the spacing plays an important role in yaml files so please double check the yaml format. – Ananthapadmanabhan May 06 '19 at 09:15

1 Answers1

0

Try putting the value in single quotes like:

foo:
  bar: 'bazz'

Since the value being read is mapped to a string variable.

Ananthapadmanabhan
  • 5,706
  • 6
  • 22
  • 39