io.micronaut.context.ApplicationContext.findBean()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(3.0k)|赞(0)|评价(0)|浏览(125)

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

ApplicationContext.findBean介绍

暂无

代码示例

代码示例来源:origin: micronaut-projects/micronaut-core

/**
 * Main method.
 * @param args The arguments
 */
public static void main(String... args) {
  // enable Graal class analysis
  System.setProperty(GraalClassLoadingReporter.GRAAL_CLASS_ANALYSIS, Boolean.TRUE.toString());
  if (ArrayUtils.isNotEmpty(args)) {
    System.setProperty(GraalClassLoadingReporter.REFLECTION_JSON_FILE, args[0]);
  }
  try {
    ApplicationContext applicationContext = ApplicationContext.run();
    // following beans may impact classloading, so load them.
    applicationContext.findBean(EmbeddedServer.class);
    applicationContext.getBeansOfType(ExecutableMethodProcessor.class);
    // finish up
    applicationContext.stop();
  } catch (Throwable e) {
    System.err.println("An error occurred analyzing class requirements: " + e.getMessage());
    e.printStackTrace(System.err);
  }
}

代码示例来源:origin: micronaut-projects/micronaut-core

/**
 * This method is designed to be called when using the {@link FunctionInitializer} from a static Application main method.
 *
 * @param args     The arguments passed to main
 * @param supplier The function that executes this function
 * @throws IOException If an error occurs
 */
protected void run(String[] args, Function<ParseContext, ?> supplier) throws IOException {
  ApplicationContext applicationContext = this.applicationContext;
  this.functionExitHandler = applicationContext.findBean(FunctionExitHandler.class).orElse(this.functionExitHandler);
  ParseContext context = new ParseContext(args);
  try {
    Object result = supplier.apply(context);
    if (result != null) {
      LocalFunctionRegistry bean = applicationContext.getBean(LocalFunctionRegistry.class);
      StreamFunctionExecutor.encode(applicationContext.getEnvironment(), bean, result.getClass(), result, System.out);
      functionExitHandler.exitWithSuccess();
    }
  } catch (Exception e) {
    functionExitHandler.exitWithError(e, context.debug);
  }
}

代码示例来源:origin: io.micronaut/runtime

@SuppressWarnings("unchecked")
  private Weigher<Object, Object> findWeigher() {
    return applicationContext.findBean(Weigher.class, Qualifiers.byName(cacheConfiguration.getCacheName()))
        .orElseGet(() -> applicationContext.findBean(Weigher.class)
            .orElse(Weigher.singletonWeigher()));
  }
}

代码示例来源:origin: micronaut-projects/micronaut-spring

@Override
public void start() {
  if (!isRunning()) {
    micronautContext.start();
    this.beanFactory = micronautContext.getBean(MicronautBeanFactory.class);
    this.environment = micronautContext.getBean(MicronautEnvironment.class);
    this.eventPublisher = micronautContext.getBean(MicronautApplicationEventPublisher.class);
    this.messageSource = micronautContext.findBean(MessageSource.class).orElse(null);
    this.startupDate = System.currentTimeMillis();
  }
}

代码示例来源:origin: io.micronaut/runtime

applicationContext.start();
Optional<EmbeddedApplication> embeddedContainerBean = applicationContext.findBean(EmbeddedApplication.class);

相关文章