Interface Environment

All Superinterfaces:
AutoCloseable, Closeable, ConversionService, LifeCycle<Environment>, MutableConversionService, PropertyResolver, ResourceLoader, ValueResolver<String>
All Known Implementing Classes:
DefaultEnvironment

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
Author:
Graeme Rocher
  • Field Details

  • Method Details

    • getActiveNames

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

      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(String pkg)
      Add an application package. Application packages are candidates for scanning for tools that need it (such as JPA).
      Parameters:
      pkg - The package to add
      Returns:
      This environment
    • addConfigurationExcludes

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

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

      Collection<String> getPackages()
      Returns:
      The application packages
    • getPlaceholderResolver

      PropertyPlaceholderResolver getPlaceholderResolver()
      Returns:
      The placeholder resolver
    • refreshAndDiff

      Map<String,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(String name, @Nullable @Nullable Map<String,? super Object> values)
      Add a property source for the given map.
      Parameters:
      name - The name
      values - The values
      Returns:
      This environment
    • addPackage

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

      default Stream<Class<?>> scan(Class<? extends 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 Stream<Class<?>> scan(Class<? extends Annotation> annotation, 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 ClassLoader getClassLoader()
      Returns:
      The class loader for the environment
    • isPresent

      default boolean isPresent(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
    • getPropertySourceLoaders

      Collection<PropertySourceLoader> getPropertySourceLoaders()
      Obtains the PropertySourceLoader instances.
      Returns:
      A collection of PropertySourceLoader