org.springframework.context.annotation.AnnotationConfigApplicationContext.stop()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(84)

本文整理了Java中org.springframework.context.annotation.AnnotationConfigApplicationContext.stop()方法的一些代码示例,展示了AnnotationConfigApplicationContext.stop()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AnnotationConfigApplicationContext.stop()方法的具体详情如下:
包路径:org.springframework.context.annotation.AnnotationConfigApplicationContext
类名称:AnnotationConfigApplicationContext
方法名:stop

AnnotationConfigApplicationContext.stop介绍

暂无

代码示例

代码示例来源:origin: com.github.mrstampy/hit

/**
 * Stops the application context.
 */
protected void stop() {
 if (applicationContext == null) {
  log.error("Application context not initialized");
  return;
 }
 log.info("Stopping context");
 applicationContext.stop();
 applicationContext.close();
 log.info("Spring context stopped");
}

代码示例来源:origin: mp911de/spring-cloud-vault-config-samples

public static void main(String[] args) {
  System.setProperty("spring.cloud.appId", "my-cloud-app");
  System.setProperty("spring.cloud.my-vault-service",
      "https://localhost:8200?token=my-token");
  AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
      MyConfig.class, ClientComponent.class);
  context.start();
  ClientComponent component = context.getBean(ClientComponent.class);
  log.info("VaultOperations (hash): {}", component.getVaultOperations());
  context.stop();
}

代码示例来源:origin: remoting/dubbox

public void stop() {
  try {
    if (context != null) {
      context.stop();
      context.close();
      context = null;
    }
  } catch (Throwable e) {
    logger.error(e.getMessage(), e);
  }
}

代码示例来源:origin: remoting/dubbox

public void stop() {
  try {
    if (context != null) {
      context.stop();
      context.close();
      context = null;
    }
  } catch (Throwable e) {
    logger.error(e.getMessage(), e);
  }
}

代码示例来源:origin: amoAHCP/spring-vertx-ext

/**
 * When a verticle will be stopped the stop() method will be executed.
 * In this case check if there is a running spring context, if so close it.
 * @param joinPoint the verticle stop method
 */
@After(value = "execution(* io.vertx.core.Verticle+.stop())")
public void afterStop(JoinPoint joinPoint) {
  final Object target = joinPoint.getTarget();
  log.debug("Stop invoked - Terminating spring context for verticle");
  if (target.getClass().isAnnotationPresent(SpringVerticle.class)) {
    if (AnnotationConfigApplicationContext.class.isAssignableFrom(context.getClass())) {
      final ApplicationContext parent = AnnotationConfigApplicationContext.class.cast(context).getParent();
      if (parent == null) {
        AnnotationConfigApplicationContext.class.cast(context).stop();
      } else {
        if (GenericApplicationContext.class.isAssignableFrom(parent.getClass())) {
          GenericApplicationContext.class.cast(parent).stop();
        }
      }
    }
  }
}

代码示例来源:origin: mp911de/spring-cloud-vault-config-samples

public static void main(String[] args) {
  AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
      VaultConnectorsConfig.class, VaultConfig.class);
  context.start();
  Cloud cloud = context.getBean(Cloud.class);
  SslConfiguration sslConfiguration = context.getBean(SslConfiguration.class);
  VaultServiceInfo vaultServiceInfo = (VaultServiceInfo) cloud
      .getServiceInfos(VaultOperations.class).get(0);
  VaultServiceConnectorConfig config = VaultServiceConnectorConfig.builder()
      .sslConfiguration(sslConfiguration).build();
  VaultOperations vaultOperations = cloud
      .getSingletonServiceConnector(VaultOperations.class, config);
  VaultResponse response = vaultOperations
      .read(vaultServiceInfo.getBackends().get("generic") + "/application");
  log.info("Retrieved app-key: {}", response.getData().get("app-key"));
  context.stop();
}

代码示例来源:origin: mp911de/spring-cloud-vault-config-samples

public static void main(String[] args) {
  AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
      VaultConfiguration.class);
  context.start();
  VaultTemplate vaultTemplate = context.getBean(VaultTemplate.class);
  MySecretData mySecretData = new MySecretData();
  mySecretData.setUsername("walter");
  mySecretData.setPassword("white");
  vaultTemplate.write(
      "secret/myapplication/user/3128", mySecretData);
  log.info("Wrote data to Vault");
  VaultResponseSupport<MySecretData> response = vaultTemplate.read(
      "secret/myapplication/user/3128", MySecretData.class);
  log.info("Retrieved data {} from Vault", response.getData().getUsername());
  context.stop();
}

代码示例来源:origin: mp911de/spring-cloud-vault-config-samples

public static void main(String[] args) {
  AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
      VaultConfiguration.class);
  context.start();
  PersonRepository repository = context.getBean(PersonRepository.class);
  Person person = new Person();
  person.setId("heisenberg");
  person.setFirstname("Walter");
  person.setLastname("White");
  person.setSsn("1234");
  repository.save(person);
  log.info("Wrote data to Vault");
  VaultTemplate template = context.getBean(VaultTemplate.class);
  VaultResponse response = template.read("secret/person/heisenberg");
  log.info("Retrieved data {} from Vault via Template API", response.getData());
  Optional<Person> loaded = repository.findById(person.getId());
  log.info("Retrieved data {} from Vault via Repository", loaded.get());
  context.stop();
}

代码示例来源:origin: alien4cloud/alien4cloud

private void unloadPlugin(String pluginId, boolean disable, boolean remove) {
  ManagedPlugin managedPlugin = pluginContexts.get(pluginId);
  if (managedPlugin != null) {
    // send events to plugin loading callbacks
    for (IPluginLoadingCallback callback : SpringUtils.getBeansOfType(alienContext, IPluginLoadingCallback.class)) {
      callback.onPluginClosed(managedPlugin);
    }
    managedPlugin.getPluginContext().stop();
    // destroy the plugin context
    managedPlugin.getPluginContext().destroy();
  }
  // unlink the plugin
  for (PluginLinker linker : linkers) {
    linker.linker.unlink(pluginId);
  }
  // eventually remove it from elastic search and disk.
  if (remove) {
    removePlugin(pluginId, true);
  } else if (disable) {
    disablePlugin(pluginId);
  }
  pluginContexts.remove(pluginId);
}

相关文章

微信公众号

最新文章

更多

AnnotationConfigApplicationContext类方法