List of usage examples for org.springframework.context ApplicationContext getId
@Nullable String getId();
From source file:org.jasig.springframework.test.ServletPortletAwareTester.java
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { logger.debug("{} - ApplicationContext is a {}", this.name, applicationContext.getClass()); logger.debug("{} - ApplicationContext id is {}", this.name, applicationContext.getId()); String contextIds = applicationContext.getId(); ApplicationContext parent = applicationContext.getParent(); if (parent != null) { while (parent != null) { contextIds = contextIds + " => " + parent.getId(); parent = parent.getParent(); }/*from w ww . j a va 2 s. c o m*/ logger.debug("{} - ApplicationContext heirarchy is {}", this.name, contextIds); } else { logger.debug("{} - ApplicationContext has no parent", this.name); } }
From source file:org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.java
private ApplicationConfigurationProperties extract(ApplicationContext context) { Map<String, ContextConfigurationProperties> contextProperties = new HashMap<>(); ApplicationContext target = context; while (target != null) { contextProperties.put(target.getId(), describeConfigurationProperties(target, getObjectMapper())); target = target.getParent();/*from ww w . j av a 2 s.c om*/ } return new ApplicationConfigurationProperties(contextProperties); }
From source file:org.springframework.cloud.zookeeper.discovery.ZookeeperServiceDiscovery.java
/** * One can override this method to provide custom way of registering a service * instance (e.g. when no payload is required). *//*from w ww .j a va 2 s.com*/ public void configureServiceInstance(AtomicReference<ServiceInstance<ZookeeperInstance>> serviceInstance, String appName, ApplicationContext context, AtomicInteger port, String host, UriSpec uriSpec) { // @formatter:off try { ZookeeperInstance zookeeperInstance = new ZookeeperInstance(context.getId(), appName, this.properties.getMetadata()); if (StringUtils.hasText(this.properties.getInitialStatus())) { zookeeperInstance.getMetadata().put(INSTANCE_STATUS_KEY, this.properties.getInitialStatus()); } serviceInstance.set(ServiceInstance.<ZookeeperInstance>builder().name(appName) .payload(zookeeperInstance).port(port.get()).address(host).uriSpec(uriSpec).build()); } catch (Exception e) { ReflectionUtils.rethrowRuntimeException(e); } // @formatter:on }
From source file:org.springframework.data.gemfire.support.SpringContextBootstrappingInitializer.java
/** * Null-safe operation used to get the ID of the Spring ApplicationContext. * * @param applicationContext the Spring ApplicationContext from which to get the ID. * @return the ID of the given Spring ApplicationContext or null if the ApplicationContext reference is null. * @see org.springframework.context.ApplicationContext#getId() *//*from w w w . j a v a 2 s. c om*/ String nullSafeGetApplicationContextId(ApplicationContext applicationContext) { return (applicationContext != null ? applicationContext.getId() : null); }
From source file:org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerTest.java
@Test public void testNullSafeGetApplicationContextIdWithNonNullReference() { ApplicationContext mockApplicationContext = mock(ApplicationContext.class, "testNullSafeGetApplicationContextIdWithNonNullReference"); when(mockApplicationContext.getId()).thenReturn("testNullSafeGetApplicationContextIdWithNonNullReference"); assertEquals("testNullSafeGetApplicationContextIdWithNonNullReference", new SpringContextBootstrappingInitializer() .nullSafeGetApplicationContextId(mockApplicationContext)); }
From source file:org.springframework.integration.config.IdGeneratorConfigurer.java
public synchronized void onApplicationEvent(ApplicationContextEvent event) { ApplicationContext context = event.getApplicationContext(); if (event instanceof ContextRefreshedEvent) { boolean contextHasIdGenerator = context.getBeanNamesForType(IdGenerator.class).length > 0; if (contextHasIdGenerator) { if (this.setIdGenerator(context)) { IdGeneratorConfigurer.generatorContextId.add(context.getId()); }//from w w w .j a v a 2s. co m } } else if (event instanceof ContextClosedEvent) { if (IdGeneratorConfigurer.generatorContextId.contains(context.getId())) { if (IdGeneratorConfigurer.generatorContextId.size() == 1) { this.unsetIdGenerator(); } IdGeneratorConfigurer.generatorContextId.remove(context.getId()); } } }
From source file:org.unitils.database.core.impl.SpringApplicationContextDataSourceProvider.java
@SuppressWarnings("unchecked") protected Map<String, DataSourceWrapper> getDataSourceWrappers() { ApplicationContext applicationContext = springTestManager.getApplicationContext(); if (applicationContext == null) { throw new UnitilsException("No test application context found."); }//from w ww. ja v a 2 s .co m String applicationContextId = applicationContext.getId(); if (!applicationContextId.equals(currentApplicationContextId)) { currentApplicationContextId = applicationContextId; currentDataSourceWrappers = createDataSourceWrappers(applicationContext); } return currentDataSourceWrappers; }