Interface Environment

  • All Superinterfaces:
    java.lang.AutoCloseable, java.io.Closeable, io.micronaut.core.convert.ConversionService<Environment>, LifeCycle<Environment>, io.micronaut.core.value.PropertyResolver, io.micronaut.core.io.ResourceLoader, io.micronaut.core.value.ValueResolver<java.lang.String>
    All Known Implementing Classes:
    DefaultEnvironment

    public interface Environment
    extends io.micronaut.core.value.PropertyResolver, LifeCycle<Environment>, io.micronaut.core.convert.ConversionService<Environment>, io.micronaut.core.io.ResourceLoader

    The current application environment. The environment represents the loaded configuration of the application for a current list of active environment names.

    The active environment names can be obtained from the getActiveNames() method and are established from one of the following sources:

    When establishing the environment name from the class the started the application Micronaut will inspect the stacktrace. If JUnit or Spock are featured in the stacktrace the TEST environment is included. When running from Android the ANDROID environment is included.

    Since:
    1.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String AMAZON_EC2
      Cloud provider amazon ec2.
      static java.lang.String ANDROID
      The android environment.
      static java.lang.String AZURE
      Cloud provider Microsoft Azure.
      static java.lang.String BARE_METAL
      Cloud or non cloud provider on bare metal (unknown).
      static java.lang.String BOOTSTRAP_CONTEXT_PROPERTY
      Whether the bootstrap context is enabled.
      static java.lang.String BOOTSTRAP_NAME
      The default bootstrap config name.
      static java.lang.String BOOTSTRAP_NAME_PROPERTY
      System property to override the default bootstrap name.
      static java.lang.String CLI
      The cli environment.
      static java.lang.String CLOUD
      The cloud environment.
      static java.lang.String CLOUD_FOUNDRY
      Running on Cloud Foundry.
      static java.lang.String CLOUD_PLATFORM_PROPERTY
      The default bootstrap name.
      static java.lang.String DEDUCE_ENVIRONMENT_ENV
      Environment key for whether to deduce environments.
      static java.lang.String DEDUCE_ENVIRONMENT_PROPERTY
      Property for whether to deduce environments.
      static java.lang.String DEFAULT_NAME
      The default application name.
      static java.lang.String DEVELOPMENT
      The development environment.
      static java.lang.String DIGITAL_OCEAN
      Cloud provider Digital Ocean.
      static java.lang.String ENVIRONMENTS_ENV
      The environment key that stores additional environments.
      static java.lang.String ENVIRONMENTS_PROPERTY
      The property that stores additional environments.
      static java.lang.String FUNCTION
      The application is executing as a function.
      static java.lang.String GAE
      Cloud provider for google app engine.
      static java.lang.String GOOGLE_COMPUTE
      Cloud provider google compute instance.
      static java.lang.String HEROKU
      Running on Heroku.
      static java.lang.String HOSTNAME
      The host name environment variable.
      static java.lang.String IBM
      Cloud provider IBM cloud.
      static java.lang.String KUBERNETES
      Running on Kubernetes.
      static java.lang.String MICRONAUT
      Constant for the name micronaut.
      static java.lang.String ORACLE_CLOUD
      Cloud provider Oracle Cloud.
      static java.lang.String PROPERTY_SOURCES_KEY
      The key used to load additional property sources.
      static java.lang.String TEST
      The test environment.
      • Fields inherited from interface io.micronaut.core.convert.ConversionService

        SHARED
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      Environment addConfigurationExcludes​(java.lang.String... names)
      Exclude configurations by name.
      Environment addConfigurationIncludes​(java.lang.String... names)
      Exclude configurations by name.
      default Environment addPackage​(java.lang.Package pkg)
      Add an application package.
      Environment addPackage​(java.lang.String pkg)
      Add an application package.
      Environment addPropertySource​(PropertySource propertySource)
      Adds a property source to this environment.
      default Environment addPropertySource​(java.lang.String name, java.util.Map<java.lang.String,​? super java.lang.Object> values)
      Add a property source for the given map.
      java.util.Set<java.lang.String> getActiveNames()
      Should respect the order as provided.
      default java.lang.ClassLoader getClassLoader()  
      java.util.Collection<java.lang.String> getPackages()  
      PropertyPlaceholderResolver getPlaceholderResolver()  
      java.util.Collection<PropertySourceLoader> getPropertySourceLoaders()
      Obtains the PropertySourceLoader instances.
      java.util.Collection<PropertySource> getPropertySources()  
      boolean isActive​(BeanConfiguration configuration)
      Whether the current environment includes the given configuration.
      default boolean isPresent​(java.lang.String className)
      Check whether the given class is present within this environment.
      java.util.Map<java.lang.String,​java.lang.Object> refreshAndDiff()
      Refresh the environment from the list of PropertySource instances and return a diff of the changes.
      Environment removePropertySource​(PropertySource propertySource)
      Removes a property source from this environment.
      default java.util.stream.Stream<java.lang.Class<?>> scan​(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
      Scan the current environment for classes annotated with the given annotation.
      default java.util.stream.Stream<java.lang.Class<?>> scan​(java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.String... packages)
      Scan the current environment for classes annotated with the given annotation.
      • Methods inherited from interface io.micronaut.core.convert.ConversionService

        addConverter, addConverter, canConvert, convert, convert, convert, convert, convertRequired, convertRequired
      • Methods inherited from interface io.micronaut.core.value.PropertyResolver

        containsProperties, containsProperty, get, getProperties, getProperties, getProperty, getProperty, getProperty, getProperty, getProperty, getPropertyEntries, getRequiredProperty
      • Methods inherited from interface io.micronaut.core.io.ResourceLoader

        forBase, getResource, getResourceAsStream, getResources, supportsPrefix
      • Methods inherited from interface io.micronaut.core.value.ValueResolver

        get, get, get
    • Field Detail

      • MICRONAUT

        static final java.lang.String MICRONAUT
        Constant for the name micronaut.
        See Also:
        Constant Field Values
      • DEVELOPMENT

        static final java.lang.String DEVELOPMENT
        The development environment.
        See Also:
        Constant Field Values
      • ANDROID

        static final java.lang.String ANDROID
        The android environment.
        See Also:
        Constant Field Values
      • FUNCTION

        static final java.lang.String FUNCTION
        The application is executing as a function.
        See Also:
        Constant Field Values
      • BOOTSTRAP_NAME_PROPERTY

        static final java.lang.String BOOTSTRAP_NAME_PROPERTY
        System property to override the default bootstrap name.
        See Also:
        Constant Field Values
      • BOOTSTRAP_CONTEXT_PROPERTY

        static final java.lang.String BOOTSTRAP_CONTEXT_PROPERTY
        Whether the bootstrap context is enabled.
        See Also:
        Constant Field Values
      • CLOUD_PLATFORM_PROPERTY

        static final java.lang.String CLOUD_PLATFORM_PROPERTY
        The default bootstrap name.
        See Also:
        Constant Field Values
      • ENVIRONMENTS_PROPERTY

        static final java.lang.String ENVIRONMENTS_PROPERTY
        The property that stores additional environments.
        See Also:
        Constant Field Values
      • ENVIRONMENTS_ENV

        static final java.lang.String ENVIRONMENTS_ENV
        The environment key that stores additional environments.
        See Also:
        Constant Field Values
      • BOOTSTRAP_NAME

        static final java.lang.String BOOTSTRAP_NAME
        The default bootstrap config name.
        See Also:
        Constant Field Values
      • DEFAULT_NAME

        static final java.lang.String DEFAULT_NAME
        The default application name.
        See Also:
        Constant Field Values
      • GOOGLE_COMPUTE

        static final java.lang.String GOOGLE_COMPUTE
        Cloud provider google compute instance.
        See Also:
        Constant Field Values
      • GAE

        static final java.lang.String GAE
        Cloud provider for google app engine.
        See Also:
        Constant Field Values
      • AMAZON_EC2

        static final java.lang.String AMAZON_EC2
        Cloud provider amazon ec2.
        See Also:
        Constant Field Values
      • AZURE

        static final java.lang.String AZURE
        Cloud provider Microsoft Azure.
        See Also:
        Constant Field Values
      • ORACLE_CLOUD

        static final java.lang.String ORACLE_CLOUD
        Cloud provider Oracle Cloud.
        See Also:
        Constant Field Values
      • DIGITAL_OCEAN

        static final java.lang.String DIGITAL_OCEAN
        Cloud provider Digital Ocean.
        See Also:
        Constant Field Values
      • BARE_METAL

        static final java.lang.String BARE_METAL
        Cloud or non cloud provider on bare metal (unknown).
        See Also:
        Constant Field Values
      • KUBERNETES

        static final java.lang.String KUBERNETES
        Running on Kubernetes.
        See Also:
        Constant Field Values
      • CLOUD_FOUNDRY

        static final java.lang.String CLOUD_FOUNDRY
        Running on Cloud Foundry.
        See Also:
        Constant Field Values
      • PROPERTY_SOURCES_KEY

        static final java.lang.String PROPERTY_SOURCES_KEY
        The key used to load additional property sources.
        See Also:
        Constant Field Values
      • HOSTNAME

        static final java.lang.String HOSTNAME
        The host name environment variable.
        See Also:
        Constant Field Values
      • DEDUCE_ENVIRONMENT_PROPERTY

        static final java.lang.String DEDUCE_ENVIRONMENT_PROPERTY
        Property for whether to deduce environments.
        See Also:
        Constant Field Values
      • DEDUCE_ENVIRONMENT_ENV

        static final java.lang.String DEDUCE_ENVIRONMENT_ENV
        Environment key for whether to deduce environments.
        See Also:
        Constant Field Values
    • Method Detail

      • getActiveNames

        java.util.Set<java.lang.String> getActiveNames()
        Should respect the order as provided.
        Returns:
        The active environment names
      • getPropertySources

        java.util.Collection<PropertySource> getPropertySources()
        Returns:
        The active property sources
      • addPropertySource

        Environment addPropertySource​(PropertySource propertySource)
        Adds a property source to this environment.
        Parameters:
        propertySource - The property source
        Returns:
        This environment
      • removePropertySource

        Environment removePropertySource​(PropertySource propertySource)
        Removes a property source from this environment.
        Parameters:
        propertySource - The property source
        Returns:
        This environment
      • addPackage

        Environment addPackage​(java.lang.String pkg)
        Add an application package. Application packages are candidates for scanning for tools that need it (such as JPA or GORM).
        Parameters:
        pkg - The package to add
        Returns:
        This environment
      • addConfigurationExcludes

        Environment addConfigurationExcludes​(java.lang.String... names)
        Exclude configurations by name.
        Parameters:
        names - The names of the configuration
        Returns:
        This environment
      • addConfigurationIncludes

        Environment addConfigurationIncludes​(java.lang.String... names)
        Exclude configurations by name.
        Parameters:
        names - The names of the configuration
        Returns:
        This environment
      • getPackages

        java.util.Collection<java.lang.String> getPackages()
        Returns:
        The application packages
      • refreshAndDiff

        java.util.Map<java.lang.String,​java.lang.Object> refreshAndDiff()
        Refresh the environment from the list of PropertySource instances and return a diff of the changes.
        Returns:
        The values that changed
      • addPropertySource

        default Environment addPropertySource​(java.lang.String name,
                                              @Nullable
                                              java.util.Map<java.lang.String,​? super java.lang.Object> values)
        Add a property source for the given map.
        Parameters:
        name - The name
        values - The values
        Returns:
        This environment
      • addPackage

        default Environment addPackage​(java.lang.Package pkg)
        Add an application package. Application packages are candidates for scanning for tools that need it (such as JPA or GORM).
        Parameters:
        pkg - The package to add
        Returns:
        This environment
      • scan

        default java.util.stream.Stream<java.lang.Class<?>> scan​(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
        Scan the current environment for classes annotated with the given annotation. Use with care, repeated invocations should be avoided for performance reasons.
        Parameters:
        annotation - The annotation to scan
        Returns:
        The classes
      • scan

        default java.util.stream.Stream<java.lang.Class<?>> scan​(java.lang.Class<? extends java.lang.annotation.Annotation> annotation,
                                                                 java.lang.String... packages)
        Scan the current environment for classes annotated with the given annotation. Use with care, repeated invocations should be avoided for performance reasons.
        Parameters:
        annotation - The annotation to scan
        packages - The packages to scan
        Returns:
        The classes
      • getClassLoader

        default java.lang.ClassLoader getClassLoader()
        Returns:
        The class loader for the environment
      • isPresent

        default boolean isPresent​(java.lang.String className)
        Check whether the given class is present within this environment.
        Parameters:
        className - The class name
        Returns:
        True if it is
      • isActive

        boolean isActive​(BeanConfiguration configuration)
        Whether the current environment includes the given configuration.
        Parameters:
        configuration - The configuration
        Returns:
        True if it does