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

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

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

ApplicationContext.getEnvironment介绍

暂无

代码示例

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

private static void instrumentAnnotationMetadata(BeanContext beanContext, ExecutableMethod<?, ?> method) {
  if (beanContext instanceof ApplicationContext && method instanceof EnvironmentConfigurable) {
    // ensure metadata is environment aware
    ((EnvironmentConfigurable) method).configure(((ApplicationContext) beanContext).getEnvironment());
  }
}

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

/**
   * Start the environment specified.
   * @param applicationContext the application context with the environment
   * @return The environment within the context
   */
  protected Environment startEnvironment(ApplicationContext applicationContext) {
    if (!applicationContext.isRunning()) {
      if (this instanceof PropertySource) {
        applicationContext.getEnvironment().addPropertySource((PropertySource) this);
      }

      return applicationContext
          .start()
          .getEnvironment();
    } else {
      return applicationContext.getEnvironment();
    }
  }
}

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

@Override
  public boolean matches(ConditionContext context) {
    AnnotationMetadataProvider component = context.getComponent();
    BeanContext beanContext = context.getBeanContext();

    if (beanContext instanceof ApplicationContext) {
      Environment env = ((ApplicationContext) beanContext).getEnvironment();
      if (component instanceof ValueResolver) {
        Optional<String> optional = ((ValueResolver) component).get(Named.class.getName(), String.class);
        if (optional.isPresent()) {
          String serviceName = optional.get();
          String urlProp = ServiceHttpClientConfiguration.PREFIX + "." + serviceName + ".url";
          return env.containsProperty(urlProp) || env.containsProperty(urlProp + "s");
        }
      }
    }
    return true;
  }
}

代码示例来源: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: micronaut-projects/micronaut-core

this.customizableResponseTypeHandlerRegistry = customizableResponseTypeHandlerRegistry;
this.beanLocator = applicationContext;
this.environment = applicationContext.getEnvironment();
this.serverConfiguration = serverConfiguration;
this.sslConfiguration = nettyServerSslBuilder.getSslConfiguration();

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

/**
 * Allow configuration the {@link Environment}.
 *
 * @param consumer The consumer
 * @return This context
 */
default ApplicationContext environment(Consumer<Environment> consumer) {
  consumer.accept(getEnvironment());
  return this;
}

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

/**
 * Allow configuration the {@link Environment}.
 *
 * @param consumer The consumer
 * @return This context
 */
default ApplicationContext environment(Consumer<Environment> consumer) {
  consumer.accept(getEnvironment());
  return this;
}

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

/**
 * @return The {@link Environment} for the server
 */
default Environment getEnvironment() {
  return getApplicationContext().getEnvironment();
}

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

private static void instrumentAnnotationMetadata(BeanContext beanContext, ExecutableMethod<?, ?> method) {
  if (beanContext instanceof ApplicationContext && method instanceof EnvironmentConfigurable) {
    // ensure metadata is environment aware
    ((EnvironmentConfigurable) method).configure(((ApplicationContext) beanContext).getEnvironment());
  }
}

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

private static void instrumentAnnotationMetadata(BeanContext beanContext, ExecutableMethod<?, ?> method) {
  if (beanContext instanceof ApplicationContext && method instanceof EnvironmentConfigurable) {
    // ensure metadata is environment aware
    ((EnvironmentConfigurable) method).configure(((ApplicationContext) beanContext).getEnvironment());
  }
}

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

private void instrumentAnnotationMetadata(BeanContext context, Object object) {
  if (object instanceof EnvironmentConfigurable && context instanceof ApplicationContext) {
    ((EnvironmentConfigurable) object).configure(((ApplicationContext) context).getEnvironment());
  }
}

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

/**
 * @param executionHandleLocator The execution handler locator
 * @param uriNamingStrategy The URI naming strategy
 * @param conversionService The conversion service
 */
public DefaultRouteBuilder(ExecutionHandleLocator executionHandleLocator, UriNamingStrategy uriNamingStrategy, ConversionService<?> conversionService) {
  this.executionHandleLocator = executionHandleLocator;
  this.uriNamingStrategy = uriNamingStrategy;
  this.conversionService = conversionService;
  if (executionHandleLocator instanceof ApplicationContext) {
    ApplicationContext applicationContext = (ApplicationContext) executionHandleLocator;
    Environment environment = applicationContext.getEnvironment();
    defaultCharset = environment.get("micronaut.application.default-charset", Charset.class, StandardCharsets.UTF_8);
  } else {
    defaultCharset = StandardCharsets.UTF_8;
  }
}

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

@Override
public BeanDefinition load(BeanContext context) {
  BeanDefinition definition = load();
  if (context instanceof ApplicationContext && definition instanceof EnvironmentConfigurable) {
    ((EnvironmentConfigurable) definition).configure(((ApplicationContext) context).getEnvironment());
  }
  return definition;
}

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

@Override
public BeanDefinition load(BeanContext context) {
  BeanDefinition definition = load();
  if (context instanceof ApplicationContext && definition instanceof EnvironmentConfigurable) {
    ((EnvironmentConfigurable) definition).configure(((ApplicationContext) context).getEnvironment());
  }
  return definition;
}

代码示例来源:origin: io.micronaut/micronaut-http-client

@Override
  public boolean matches(ConditionContext context) {
    AnnotationMetadataProvider component = context.getComponent();
    BeanContext beanContext = context.getBeanContext();

    if (beanContext instanceof ApplicationContext) {
      Environment env = ((ApplicationContext) beanContext).getEnvironment();
      if (component instanceof ValueResolver) {
        Optional<String> optional = ((ValueResolver) component).get(Named.class.getName(), String.class);
        if (optional.isPresent()) {
          String serviceName = optional.get();
          String urlProp = ServiceHttpClientConfiguration.PREFIX + "." + serviceName + ".url";
          return env.containsProperty(urlProp) || env.containsProperty(urlProp + "s");
        }
      }
    }
    return true;
  }
}

代码示例来源:origin: io.micronaut/http-client

@Override
  public boolean matches(ConditionContext context) {
    AnnotationMetadataProvider component = context.getComponent();
    BeanContext beanContext = context.getBeanContext();

    if (beanContext instanceof ApplicationContext) {
      Environment env = ((ApplicationContext) beanContext).getEnvironment();
      if (component instanceof ValueResolver) {
        Optional<String> optional = ((ValueResolver) component).get(Named.class.getName(), String.class);
        if (optional.isPresent()) {
          String serviceName = optional.get();
          String urlProp = ServiceHttpClientConfiguration.PREFIX + "." + serviceName + ".url";
          return env.containsProperty(urlProp) || env.containsProperty(urlProp + "s");
        }
      }
    }
    return true;
  }
}

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

private boolean matchesPresenceOfEntities(ConditionContext context, AnnotationValue<Requires> annotationValue) {
  if (annotationValue.contains("entities")) {
    Optional<AnnotationClassValue[]> classNames = annotationValue.get("entities", AnnotationClassValue[].class);
    if (classNames.isPresent()) {
      BeanContext beanContext = context.getBeanContext();
      if (beanContext instanceof ApplicationContext) {
        ApplicationContext applicationContext = (ApplicationContext) beanContext;
        final AnnotationClassValue[] classValues = classNames.get();
        for (AnnotationClassValue<?> classValue : classValues) {
          final Optional<? extends Class<?>> entityType = classValue.getType();
          if (!entityType.isPresent()) {
            context.fail("Annotation type [" + classValue.getName() + "] not present on classpath");
            return false;
          } else {
            Environment environment = applicationContext.getEnvironment();
            Class annotationType = entityType.get();
            if (!environment.scan(annotationType).findFirst().isPresent()) {
              context.fail("No entities found in packages [" + String.join(", ", environment.getPackages()) + "] for annotation: " + annotationType);
              return false;
            }
          }
        }
      }
    }
  }
  return true;
}

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

private boolean matchesPresenceOfEntities(ConditionContext context, AnnotationValue<Requires> annotationValue) {
  if (annotationValue.contains("entities")) {
    Optional<AnnotationClassValue[]> classNames = annotationValue.get("entities", AnnotationClassValue[].class);
    if (classNames.isPresent()) {
      BeanContext beanContext = context.getBeanContext();
      if (beanContext instanceof ApplicationContext) {
        ApplicationContext applicationContext = (ApplicationContext) beanContext;
        final AnnotationClassValue[] classValues = classNames.get();
        for (AnnotationClassValue<?> classValue : classValues) {
          final Optional<? extends Class<?>> entityType = classValue.getType();
          if (!entityType.isPresent()) {
            context.fail("Annotation type [" + classValue.getName() + "] not present on classpath");
            return false;
          } else {
            Environment environment = applicationContext.getEnvironment();
            Class annotationType = entityType.get();
            if (!environment.scan(annotationType).findFirst().isPresent()) {
              context.fail("No entities found in packages [" + String.join(", ", environment.getPackages()) + "] for annotation: " + annotationType);
              return false;
            }
          }
        }
      }
    }
  }
  return true;
}

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

if (beanContext instanceof ApplicationContext) {
    ApplicationContext applicationContext = (ApplicationContext) beanContext;
    Environment environment = applicationContext.getEnvironment();
    Set<String> activeNames = environment.getActiveNames();
    boolean result = Arrays.stream(env).anyMatch(s -> !activeNames.contains(s));
if (beanContext instanceof ApplicationContext) {
  ApplicationContext applicationContext = (ApplicationContext) beanContext;
  Environment environment = applicationContext.getEnvironment();
  Set<String> activeNames = environment.getActiveNames();
  boolean result = Arrays.stream(env).anyMatch(activeNames::contains);

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

if (beanContext instanceof ApplicationContext) {
    ApplicationContext applicationContext = (ApplicationContext) beanContext;
    Environment environment = applicationContext.getEnvironment();
    Set<String> activeNames = environment.getActiveNames();
    boolean result = Arrays.stream(env).noneMatch(activeNames::contains);
if (beanContext instanceof ApplicationContext) {
  ApplicationContext applicationContext = (ApplicationContext) beanContext;
  Environment environment = applicationContext.getEnvironment();
  Set<String> activeNames = environment.getActiveNames();
  boolean result = Arrays.stream(env).anyMatch(activeNames::contains);

相关文章