本文整理了Java中org.springframework.context.ApplicationContext.getId()
方法的一些代码示例,展示了ApplicationContext.getId()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ApplicationContext.getId()
方法的具体详情如下:
包路径:org.springframework.context.ApplicationContext
类名称:ApplicationContext
方法名:getId
[英]Return the unique id of this application context.
[中]返回此应用程序上下文的唯一id。
代码示例来源:origin: org.springframework.boot/spring-boot
@Override
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
response.addHeader(HEADER_NAME, this.applicationContext.getId());
filterChain.doFilter(request, response);
}
代码示例来源:origin: spring-projects/spring-framework
result.append("{\n\"context\": \"").append(context.getId()).append("\",\n");
if (context.getParent() != null) {
result.append("\"parent\": \"").append(context.getParent().getId()).append("\",\n");
代码示例来源:origin: codecentric/spring-boot-admin
@EventListener
@Order(Ordered.LOWEST_PRECEDENCE)
public void onClosedContext(ContextClosedEvent event) {
if (event.getApplicationContext().getParent() == null ||
"bootstrap".equals(event.getApplicationContext().getParent().getId())) {
stopRegisterTask();
if (autoDeregister) {
registrator.deregister();
}
}
}
代码示例来源:origin: AxonFramework/AxonFramework
@Bean
public AxonServerConfiguration axonServerConfiguration() {
AxonServerConfiguration configuration = new AxonServerConfiguration();
configuration.setComponentName(clientName(applicationContext.getId()));
return configuration;
}
代码示例来源:origin: org.springframework/spring-context
result.append("{\n\"context\": \"").append(context.getId()).append("\",\n");
if (context.getParent() != null) {
result.append("\"parent\": \"").append(context.getParent().getId()).append("\",\n");
代码示例来源:origin: spring-projects/spring-integration
/**
* Returns the {@link ApplicationContext#getId()} if the
* {@link ApplicationContext} is available.
* @return The id, or null if there is no application context.
*/
public String getApplicationContextId() {
return this.applicationContext == null ? null : this.applicationContext.getId();
}
代码示例来源:origin: org.springframework.cloud/spring-cloud-commons
/**
* @return The serviceId of the Management Service.
*/
@Deprecated
protected String getManagementServiceId() {
// TODO: configurable management suffix
return this.context.getId() + ":management";
}
代码示例来源:origin: mercyblitz/segmentfault-lessons
@PostMapping("/bus/event/publish/user")
public boolean publishUserEvent(@RequestBody User user,
@RequestParam(value = "destination", required = false) String destination) {
String serviceInstanceId = applicationContext.getId();
UserRemoteApplicationEvent event = new UserRemoteApplicationEvent(user, serviceInstanceId, destination);
eventPublisher.publishEvent(event);
return true;
}
代码示例来源:origin: mercyblitz/segmentfault-lessons
@PostMapping("/bus/event/publish/user")
public boolean publishUserEvent(@RequestBody User user,
@RequestParam(value = "destination", required = false) String destination) {
String serviceInstanceId = applicationContext.getId();
UserRemoteApplicationEvent event = new UserRemoteApplicationEvent(user, serviceInstanceId, destination);
eventPublisher.publishEvent(event);
return true;
}
代码示例来源:origin: org.apache.camel/camel-spring
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("SpringCamelContext(").append(getName()).append(")");
if (applicationContext != null) {
sb.append(" with spring id ").append(applicationContext.getId());
}
return sb.toString();
}
代码示例来源:origin: org.springframework.cloud/spring-cloud-context
private void close() {
ApplicationContext context = this.context;
while (context instanceof Closeable) {
try {
((Closeable) context).close();
}
catch (IOException e) {
logger.error("Cannot close context: " + context.getId(), e);
}
context = context.getParent();
}
}
代码示例来源:origin: spring-projects/spring-integration
@Override
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());
}
}
}
else if (event instanceof ContextClosedEvent) {
if (IdGeneratorConfigurer.generatorContextId.contains(context.getId())) {
if (IdGeneratorConfigurer.generatorContextId.size() == 1) {
this.unsetIdGenerator();
}
IdGeneratorConfigurer.generatorContextId.remove(context.getId());
}
}
}
代码示例来源:origin: org.springframework.boot/spring-boot-actuator
private ContextMappings mappingsForContext(ApplicationContext applicationContext) {
Map<String, Object> mappings = new HashMap<>();
this.descriptionProviders
.forEach((provider) -> mappings.put(provider.getMappingName(),
provider.describeMappings(applicationContext)));
return new ContextMappings(mappings, (applicationContext.getParent() != null)
? applicationContext.getId() : null);
}
代码示例来源:origin: org.springframework.boot/spring-boot-actuator
@ReadOperation
public ApplicationFlywayBeans flywayBeans() {
ApplicationContext target = this.context;
Map<String, ContextFlywayBeans> contextFlywayBeans = new HashMap<>();
while (target != null) {
Map<String, FlywayDescriptor> flywayBeans = new HashMap<>();
target.getBeansOfType(Flyway.class).forEach((name, flyway) -> flywayBeans
.put(name, new FlywayDescriptor(flyway.info().all())));
ApplicationContext parent = target.getParent();
contextFlywayBeans.put(target.getId(), new ContextFlywayBeans(flywayBeans,
(parent != null) ? parent.getId() : null));
target = parent;
}
return new ApplicationFlywayBeans(contextFlywayBeans);
}
代码示例来源:origin: org.springframework.boot/spring-boot-actuator
@ReadOperation
public ApplicationMappings mappings() {
ApplicationContext target = this.context;
Map<String, ContextMappings> contextMappings = new HashMap<>();
while (target != null) {
contextMappings.put(target.getId(), mappingsForContext(target));
target = target.getParent();
}
return new ApplicationMappings(contextMappings);
}
代码示例来源:origin: org.springframework.boot/spring-boot-actuator
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();
}
return new ApplicationConfigurationProperties(contextProperties);
}
代码示例来源:origin: org.springframework.boot/spring-boot-actuator
@ReadOperation
public ApplicationLiquibaseBeans liquibaseBeans() {
ApplicationContext target = this.context;
Map<String, ContextLiquibaseBeans> contextBeans = new HashMap<>();
while (target != null) {
Map<String, LiquibaseBean> liquibaseBeans = new HashMap<>();
DatabaseFactory factory = DatabaseFactory.getInstance();
StandardChangeLogHistoryService service = new StandardChangeLogHistoryService();
this.context.getBeansOfType(SpringLiquibase.class)
.forEach((name, liquibase) -> liquibaseBeans.put(name,
createReport(liquibase, service, factory)));
ApplicationContext parent = target.getParent();
contextBeans.put(target.getId(), new ContextLiquibaseBeans(liquibaseBeans,
(parent != null) ? parent.getId() : null));
target = parent;
}
return new ApplicationLiquibaseBeans(contextBeans);
}
代码示例来源:origin: org.springframework.boot/spring-boot-actuator
private ContextConfigurationProperties describeConfigurationProperties(
ApplicationContext context, ObjectMapper mapper) {
ConfigurationBeanFactoryMetadata beanFactoryMetadata = getBeanFactoryMetadata(
context);
Map<String, Object> beans = getConfigurationPropertiesBeans(context,
beanFactoryMetadata);
Map<String, ConfigurationPropertiesBeanDescriptor> beanDescriptors = new HashMap<>();
beans.forEach((beanName, bean) -> {
String prefix = extractPrefix(context, beanFactoryMetadata, beanName);
beanDescriptors.put(beanName, new ConfigurationPropertiesBeanDescriptor(
prefix, sanitize(prefix, safeSerialize(mapper, bean, prefix))));
});
return new ContextConfigurationProperties(beanDescriptors,
(context.getParent() != null) ? context.getParent().getId() : null);
}
代码示例来源:origin: mercyblitz/thinking-in-spring-boot-samples
@Bean
@Lazy
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) // 将 Bean Scope 调整为原型(prototype)
public ApplicationRunner applicationRunner(ApplicationContext context) {
return args -> {
System.out.printf("当前服务端应用上下文 ID 为:%s\n", context.getId());
};
}
代码示例来源:origin: mercyblitz/thinking-in-spring-boot-samples
@EventListener(ContextRefreshedEvent.class)
public void onContextRefreshed(ContextRefreshedEvent event) {
ApplicationContext context = event.getApplicationContext();
ApplicationContext parentContext = context.getParent();
System.out.printf("当前管理端应用上下文 ID:%s,其双亲应用上下文 ID:%s\n",
context.getId(),
parentContext == null ? null : parentContext.getId()
);
}
}
内容来源于网络,如有侵权,请联系作者删除!