-1

i have something like that..

in file application.properties

  input.param.resolution=high
  input.param.size=1024

in a configuration class

  @Configuration
  public class FirstConfiguration {

  @Bean
    @ConfigurationProperties("input.param")
        Data buildDataBean() {
        return new Data();
     }
  }

my pojo

  public class Data {

      String resolution;
      String size;

     // getters and setters 
  }

I'd like to unauthorize binding when my String are not provided in properties file.. (and make Spring launch an exception)

    input.param.resolution=<nothing-here>
    input.param.size=<nothing-here>

How can i do this ?

electrode
  • 205
  • 1
  • 4
  • 16

1 Answers1

0

Try validating it as follows:

@Validated
public class Data {
    @NotNull
    String resolution;

    @NotNull
    String size;

   // getters and setters 
}

If you don't have it there already you need to add the following dependency to your project:

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-validation</artifactId> 
</dependency>
João Dias
  • 16,277
  • 6
  • 33
  • 45