class ConfigFileValidationApplicationListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {

  @Override
  public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    String configFilesString = event.getEnvironment().getProperty("spring.config.location");
    List<String> errors = new ArrayList<>();
    if (StringUtils.isBlank(configFilesString)) {
      errors.add("No config file was specified.");
    } else {
      for (String configFileString : Splitter.on(',').split(configFilesString)) {
        File configFile = new File(configFileString);
        if (!configFile.exists()) {
          errors.add("Config file " + configFileString + " does not exist.");
        } else if (!configFile.isFile()) {
          errors.add("Config file " + configFileString + " is a directory.");
        } else if (!configFile.canRead()) {
          errors.add("Config file " + configFileString + " cannot be read.");
        }
      }
    }
    if (!errors.isEmpty()) {
      throw new ConfigFileValidationException(errors);
    }
  }

}