shaddy
shaddy

Reputation: 43

Spring Boot @ConfigurationProperties Validation

I know the possibilities of using JSR303 Annotation in Spring Boot @ConfigurationProperties, but I have some use cases exceeding this possibilities:

I have a @ConfigurationProperties Bean which enables my application to have a folder configured for backups. So I need to check if that folder exists and is writeable. If it doesn't exist I want to create it.

Right now I use an init-Method with @PostConstruct and it works fine. I just wonder if there is a more declarative way of validating a ConfigurationProperties-Class.

Upvotes: 3

Views: 1754

Answers (1)

britter
britter

Reputation: 1392

If you really want to use JSR-303 annotations to validate the state of the backup folder you could use bean-validators. It's a library I've written a while ago with some additional validation annotations. It has file related annotations like @Writable which could be used to check the directory. But I agree with the comments: This should be part of the backup process, since the state of the directory could potentially change after the configuration has been loaded.

Upvotes: 1

Related Questions