org.springframework.boot.context.config.ConfigFileApplicationListener Java Examples
The following examples show how to use
org.springframework.boot.context.config.ConfigFileApplicationListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SofaArkEmbedUtils.java From sofa-lookout with Apache License 2.0 | 6 votes |
public static Properties parseSofaArkSupportProperties(String appName) { Properties properties = new Properties(); String configsStr = System.getProperty(SOFA_ARK_CONFIGS); if (configsStr != null) { JSONObject configs = JSONObject.parseObject(configsStr); String configDirStr = configs.getString("configDir"); // set CONFIG_ADDITIONAL_LOCATION_PROPERTY to ${configDir}/${appName} if (configDirStr != null) { Path configDir = Paths.get(configDirStr); String appConfigDir = configDir.resolve(appName).toAbsolutePath().toUri().toString(); properties.setProperty(ConfigFileApplicationListener.CONFIG_ADDITIONAL_LOCATION_PROPERTY, appConfigDir); } } String property = getProperty(appName + ".config-additional-location"); if (property != null) { String oldValue = properties.getProperty(ConfigFileApplicationListener.CONFIG_ADDITIONAL_LOCATION_PROPERTY); String newValue = oldValue != null ? (oldValue + "," + property) : property; properties.setProperty(ConfigFileApplicationListener.CONFIG_ADDITIONAL_LOCATION_PROPERTY, newValue); } return properties; }
Example #2
Source File: PropertySourceBootstrapConfiguration.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
private Set<String> addIncludedProfilesTo(Set<String> profiles, PropertySource<?> propertySource) { if (propertySource instanceof CompositePropertySource) { for (PropertySource<?> nestedPropertySource : ((CompositePropertySource) propertySource) .getPropertySources()) { addIncludedProfilesTo(profiles, nestedPropertySource); } } else { Collections.addAll(profiles, getProfilesForValue(propertySource.getProperty( ConfigFileApplicationListener.INCLUDE_PROFILES_PROPERTY))); } return profiles; }
Example #3
Source File: WallRideInitializer.java From wallride with Apache License 2.0 | 5 votes |
public static ConfigurableEnvironment createEnvironment(ApplicationStartingEvent event) { StandardEnvironment environment = new StandardEnvironment(); String home = environment.getProperty(WallRideProperties.HOME_PROPERTY); if (!StringUtils.hasText(home)) { //try to get config-File with wallride.home parameter under webroot String configFileHome = getConfigFileHome(event); if (configFileHome!=null) { home = configFileHome; } else { throw new IllegalStateException(WallRideProperties.HOME_PROPERTY + " is empty"); } } if (!home.endsWith("/")) { home = home + "/"; } String config = home + WallRideProperties.DEFAULT_CONFIG_PATH_NAME; String media = home + WallRideProperties.DEFAULT_MEDIA_PATH_NAME; System.setProperty(WallRideProperties.CONFIG_LOCATION_PROPERTY, config); System.setProperty(WallRideProperties.MEDIA_LOCATION_PROPERTY, media); event.getSpringApplication().getListeners().stream() .filter(listener -> listener.getClass().isAssignableFrom(ConfigFileApplicationListener.class)) .map(listener -> (ConfigFileApplicationListener) listener) .forEach(listener -> listener.setSearchLocations(DEFAULT_CONFIG_SEARCH_LOCATIONS + "," + config)); return environment; }
Example #4
Source File: NativeEnvironmentRepository.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Override public Environment findOne(String config, String profile, String label, boolean includeOrigin) { SpringApplicationBuilder builder = new SpringApplicationBuilder( PropertyPlaceholderAutoConfiguration.class); ConfigurableEnvironment environment = getEnvironment(profile); builder.environment(environment); builder.web(WebApplicationType.NONE).bannerMode(Mode.OFF); if (!logger.isDebugEnabled()) { // Make the mini-application startup less verbose builder.logStartupInfo(false); } String[] args = getArgs(config, profile, label); // Explicitly set the listeners (to exclude logging listener which would change // log levels in the caller) builder.application() .setListeners(Arrays.asList(new ConfigFileApplicationListener())); try (ConfigurableApplicationContext context = builder.run(args)) { environment.getPropertySources().remove("profiles"); return clean(new PassthruEnvironmentRepository(environment).findOne(config, profile, label, includeOrigin)); } catch (Exception e) { String msg = String.format( "Could not construct context for config=%s profile=%s label=%s includeOrigin=%b", config, profile, label, includeOrigin); String completeMessage = NestedExceptionUtils.buildMessage(msg, NestedExceptionUtils.getMostSpecificCause(e)); throw new FailedToConstructEnvironmentException(completeMessage, e); } }
Example #5
Source File: SourcesLogApplicationListener.java From Milkomeda with MIT License | 4 votes |
@Override public int getOrder() { // Apply after ConfigFileApplicationListener has called EnvironmentPostProcessors return ConfigFileApplicationListener.DEFAULT_ORDER + 10; }