@Override public void environmentPrepared(ConfigurableEnvironment environment) { if (!environment.containsProperty(CONFIG_PROPERTY)) { System.setProperty(CONFIG_PROPERTY, DEFAULT_NACOS_LOGBACK_LOCATION); if (logger.isInfoEnabled()) { logger.info("There is no property named \"{}\" in Spring Boot Environment, " + "and whose value is {} will be set into System's Properties", CONFIG_PROPERTY, DEFAULT_NACOS_LOGBACK_LOCATION); } } }
public boolean containsProperty(String key) { key = fullPrefixOrKey(key); return environment.containsProperty(key); }
private Set<Profile> getProfilesActivatedViaProperty() { if (!this.environment.containsProperty(ACTIVE_PROFILES_PROPERTY) && !this.environment.containsProperty(INCLUDE_PROFILES_PROPERTY)) { return Collections.emptySet(); } Binder binder = Binder.get(this.environment); Set<Profile> activeProfiles = new LinkedHashSet<>(); activeProfiles.addAll(getProfiles(binder, INCLUDE_PROFILES_PROPERTY)); activeProfiles.addAll(getProfiles(binder, ACTIVE_PROFILES_PROPERTY)); return activeProfiles; }
@Override public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { ConfigurableEnvironment environment = event.getEnvironment(); if (!environment.containsProperty("spring.mandatory-file-encoding")) { return; } String encoding = System.getProperty("file.encoding"); String desired = environment.getProperty("spring.mandatory-file-encoding"); if (encoding != null && !desired.equalsIgnoreCase(encoding)) { logger.error("System property 'file.encoding' is currently '" + encoding + "'. It should be '" + desired + "' (as defined in 'spring.mandatoryFileEncoding')."); logger.error("Environment variable LANG is '" + System.getenv("LANG") + "'. You could use a locale setting that matches encoding='" + desired + "'."); logger.error("Environment variable LC_ALL is '" + System.getenv("LC_ALL") + "'. You could use a locale setting that matches encoding='" + desired + "'."); throw new IllegalStateException( "The Java Virtual Machine has not been configured to use the " + "desired default character encoding (" + desired + ")."); } }
if (commonContext.getEnvironment().containsProperty("configservice")) { ConfigurableApplicationContext configContext = new SpringApplicationBuilder(ConfigServiceApplication.class).parent(commonContext) if (commonContext.getEnvironment().containsProperty("adminservice")) { ConfigurableApplicationContext adminContext = new SpringApplicationBuilder(AdminServiceApplication.class).parent(commonContext) if (commonContext.getEnvironment().containsProperty("portal")) { ConfigurableApplicationContext portalContext = new SpringApplicationBuilder(PortalApplication.class).parent(commonContext)
@Test public void withIgnoredPropertySource() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithIgnoredPropertySource.class); assertThat(ctx.getEnvironment().containsProperty("from.p1"), is(true)); assertThat(ctx.getEnvironment().containsProperty("from.p2"), is(true)); }
private Set<String> getSearchLocations() { if (this.environment.containsProperty(CONFIG_LOCATION_PROPERTY)) { return getSearchLocations(CONFIG_LOCATION_PROPERTY); } Set<String> locations = getSearchLocations( CONFIG_ADDITIONAL_LOCATION_PROPERTY); locations.addAll( asResolvedSet(ConfigFileApplicationListener.this.searchLocations, DEFAULT_SEARCH_LOCATIONS)); return locations; }
protected void applySpringProfiles(ConfigurableEnvironment environment, ServletContext servletContext) { String systemProfiles = System.getProperty("spring.profiles.active"); environment.setDefaultProfiles(new String[0]); if (environment.containsProperty("spring_profiles")) { String profiles = environment.getProperty("spring_profiles"); servletContext.log("Setting active profiles: " + profiles); environment.setActiveProfiles(StringUtils.tokenizeToStringArray(profiles, ",", true, true)); } else { if (isEmpty(systemProfiles)) { environment.setActiveProfiles("hsqldb"); } else { environment.setActiveProfiles(commaDelimitedListToStringArray(systemProfiles)); } } }
private Set<String> getSearchLocations(String propertyName) { Set<String> locations = new LinkedHashSet<>(); if (this.environment.containsProperty(propertyName)) { for (String path : asResolvedSet( this.environment.getProperty(propertyName), null)) { if (!path.contains("$")) { path = StringUtils.cleanPath(path); if (!ResourceUtils.isUrl(path)) { path = ResourceUtils.FILE_URL_PREFIX + path; } } locations.add(path); } } return locations; }
if (environment.containsProperty("logging.file")) { String location = environment.getProperty("logging.file"); servletContext.log("Setting LOG_FILE: " + location); System.setProperty("LOG_FILE", location); } else if (environment.containsProperty("logging.path")) { String location = environment.getProperty("logging.path"); servletContext.log("Setting LOG_PATH: " + location); System.setProperty("LOG_PATH", location); } else if (environment.containsProperty("logging.config")) {
@Test public void withSameSourceImportedInDifferentOrder() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithSameSourceImportedInDifferentOrder.class); assertThat(ctx.getEnvironment().containsProperty("from.p1"), is(true)); assertThat(ctx.getEnvironment().containsProperty("from.p2"), is(true)); assertThat(ctx.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean")); }
@Test public void withNameAndMultipleResourceLocations() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithNameAndMultipleResourceLocations.class); assertThat(ctx.getEnvironment().containsProperty("from.p1"), is(true)); assertThat(ctx.getEnvironment().containsProperty("from.p2"), is(true)); // p2 should 'win' as it was registered last assertThat(ctx.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean")); }
private Set<String> getSearchNames() { if (this.environment.containsProperty(CONFIG_NAME_PROPERTY)) { String property = this.environment.getProperty(CONFIG_NAME_PROPERTY); return asResolvedSet(property, null); } return asResolvedSet(ConfigFileApplicationListener.this.names, DEFAULT_NAMES); }
@Test public void withPropertySources() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithPropertySources.class); assertThat(ctx.getEnvironment().containsProperty("from.p1"), is(true)); assertThat(ctx.getEnvironment().containsProperty("from.p2"), is(true)); // p2 should 'win' as it was registered last assertThat(ctx.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean")); }
@Test public void withMultipleResourceLocations() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithMultipleResourceLocations.class); assertThat(ctx.getEnvironment().containsProperty("from.p1"), is(true)); assertThat(ctx.getEnvironment().containsProperty("from.p2"), is(true)); // p2 should 'win' as it was registered last assertThat(ctx.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean")); }
@Test public void withNamedPropertySources() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithNamedPropertySources.class); assertThat(ctx.getEnvironment().containsProperty("from.p1"), is(true)); assertThat(ctx.getEnvironment().containsProperty("from.p2"), is(true)); // p2 should 'win' as it was registered last assertThat(ctx.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean")); }
boolean mapQuestApiKeyDefined = env.containsProperty("mapquest.apikey");
@Override public boolean containsProperty(String key) { return delegate.containsProperty(key); }
@Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { if (isLocalApplication(environment)) { if (canAddProperties(environment)) { logger.info("Devtools property defaults active! Set '" + ENABLED + "' to 'false' to disable"); environment.getPropertySources() .addLast(new MapPropertySource("devtools", PROPERTIES)); } if (isWebApplication(environment) && !environment.containsProperty(WEB_LOGGING)) { logger.info("For additional web related logging consider " + "setting the '" + WEB_LOGGING + "' property to 'DEBUG'"); } } }
private void initLog4Jdbc() { for (final String property : PROPERTIES_TO_COPY) { if (this.environment.containsProperty(property)) { System.setProperty(property, this.environment.getProperty(property)); } } System.setProperty("log4jdbc.spylogdelegator.name", this.environment .getProperty("log4jdbc.spylogdelegator.name", Slf4jSpyLogDelegator.class.getName())); }