/** * Load all {@link PropertyFileConfig}s which are registered via * {@code java.util.ServiceLoader}. */ private void registerPropertyFileConfigs() { List<? extends PropertyFileConfig> propertyFileConfigs = ServiceUtils.loadServiceImplementations(PropertyFileConfig.class); for (PropertyFileConfig propertyFileConfig : propertyFileConfigs) { EnvironmentPropertyConfigSourceProvider environmentPropertyConfigSourceProvider = new EnvironmentPropertyConfigSourceProvider(propertyFileConfig.getPropertyFileName(), propertyFileConfig.isOptional()); configSources.addAll(environmentPropertyConfigSourceProvider.getConfigSources()); } }
/** * @return create an instance of the given {@link PropertyFileConfig} and return all it's ConfigSources. */ private List<ConfigSource> createPropertyConfigSource(Class<? extends PropertyFileConfig> propertyFileConfigClass) { try { PropertyFileConfig propertyFileConfig = propertyFileConfigClass.newInstance(); EnvironmentPropertyConfigSourceProvider environmentPropertyConfigSourceProvider = new EnvironmentPropertyConfigSourceProvider(propertyFileConfig.getPropertyFileName()); return environmentPropertyConfigSourceProvider.getConfigSources(); } catch (InstantiationException e) { throw new RuntimeException(CANNOT_CREATE_CONFIG_SOURCE_FOR_CUSTOM_PROPERTY_FILE_CONFIG + propertyFileConfigClass.getName(), e); } catch (IllegalAccessException e) { throw new RuntimeException(CANNOT_CREATE_CONFIG_SOURCE_FOR_CUSTOM_PROPERTY_FILE_CONFIG + propertyFileConfigClass.getName(), e); } }
/** * @return create an instance of the given {@link PropertyFileConfig} and return all it's ConfigSources. */ private List<ConfigSource> createPropertyConfigSource(Class<? extends PropertyFileConfig> propertyFileConfigClass) { String fileName = ""; try { PropertyFileConfig propertyFileConfig = propertyFileConfigClass.newInstance(); fileName = propertyFileConfig.getPropertyFileName(); EnvironmentPropertyConfigSourceProvider environmentPropertyConfigSourceProvider = new EnvironmentPropertyConfigSourceProvider(fileName, propertyFileConfig.isOptional()); return environmentPropertyConfigSourceProvider.getConfigSources(); } catch (InstantiationException e) { throw new RuntimeException(CANNOT_CREATE_CONFIG_SOURCE_FOR_CUSTOM_PROPERTY_FILE_CONFIG + propertyFileConfigClass.getName(), e); } catch (IllegalAccessException e) { throw new RuntimeException(CANNOT_CREATE_CONFIG_SOURCE_FOR_CUSTOM_PROPERTY_FILE_CONFIG + propertyFileConfigClass.getName(), e); } catch (IllegalStateException e) { throw new IllegalStateException( propertyFileConfigClass.getName() + " points to an invalid file: '" + fileName + "'", e); } }