My Spring application depends on certain environment variables that needs to have been set before application launch.
For eg. consider the following controller:
@Controller public class FileUploadController { /** Path to which all data will be uploaded **/ private Path appDataPath; public FileUploadController(){ // Extract the App Data path from environment variables Map<String, String> environmentVariables = System.getenv(); if (environmentVariables.containsKey("MYAPP_DATA_DIR")) { String dataPath = environmentVariables.get("MYAPP_DATA_DIR"); appDataPath = Paths.get(dataPath); } else { // TODO: Throw an exception to terminate app } } } What exception do I need to throw in the code above to terminate application startup?
@Valueand the application will automatically blow up when it isn't set, you are just complicating things.