We're building a Spring-based application which will be delivered to end users as a distribution package. Users are responsible for properly configuring whatever needs to be configured (it's mostly about various filesystem locations, folder access permissions, etc). There's a good idea to make the app help users understand what is not configured or which parts of configuration are invalid.
Our current approach is a custom ApplicationContextInitializer
which does all the environment validation "manually" and then registers few "low level" beans in the application context explicitly. If something is wrong, initializer throws, exception is caught somewhere in main()
, interpreted (converted into plain English) and then displayed.
While this approach works fine, I'm wondering if there are any best practices to minimize hand-written code and use Spring whenever possible.
Here's an illustrative example. The application requires a folder for file uploads. This means:
- There should be a configuration file
- This file should be accessible by the app
- This file should have no syntax errors
- This file should explicitly define some specific property (let it be
app.uploads.folder
) - This property should describe the existing filesystem entity
- This entity should be a folder
- The app should have read/write access to this folder
Does Spring provide any tools to implement this sort of validation easily?