TX T
TX T

Reputation: 817

Declare bean with @Valid

is there a way to valid the properties bean?

@Data
public class ProjectProperties {
    @NotBlank
    @NotEmpty
    private String description;
}

create the bean with:

@Bean
@ConfigurationProperties(prefix = "project")
@Valid
public ProjectProperties getProjectProperties() {
    return new ProjectProperties();
}

and my application.properties:

project.description =

Is there different way to make the validation work?

Upvotes: 0

Views: 79

Answers (1)

ketrox
ketrox

Reputation: 929

@Data
@Validated
public class ProjectProperties {
    @NotBlank
    @NotEmpty
    private String description;
}

Upvotes: 1

Related Questions