Class DefaultApplicationContext

    • Constructor Detail

      • DefaultApplicationContext

        public DefaultApplicationContext​(@NonNull
                                         java.lang.String... environmentNames)
        Construct a new ApplicationContext for the given environment name.
        Parameters:
        environmentNames - The environment names
      • DefaultApplicationContext

        public DefaultApplicationContext​(@NonNull
                                         io.micronaut.core.io.scan.ClassPathResourceLoader resourceLoader,
                                         @NonNull
                                         java.lang.String... environmentNames)
        Construct a new ApplicationContext for the given environment name and classloader.
        Parameters:
        environmentNames - The environment names
        resourceLoader - The class loader
      • DefaultApplicationContext

        public DefaultApplicationContext​(@NonNull
                                         ApplicationContextConfiguration configuration)
        Construct a new ApplicationContext for the given environment name and classloader.
        Parameters:
        configuration - The application context configuration
    • Method Detail

      • registerSingleton

        @NonNull
        public <T> ApplicationContext registerSingleton​(@NonNull
                                                        java.lang.Class<T> type,
                                                        @NonNull
                                                        T singleton,
                                                        @Nullable
                                                        Qualifier<T> qualifier,
                                                        boolean inject)
        Description copied from interface: BeanDefinitionRegistry

        Registers a new singleton bean at runtime. This method expects that the bean definition data will have been compiled ahead of time.

        If bean definition data is found the method will perform dependency injection on the instance followed by invoking any PostConstruct hooks.

        If no bean definition data is found the bean is registered as is.

        Specified by:
        registerSingleton in interface ApplicationContext
        Specified by:
        registerSingleton in interface BeanContext
        Specified by:
        registerSingleton in interface BeanDefinitionRegistry
        Overrides:
        registerSingleton in class DefaultBeanContext
        Type Parameters:
        T - The concrete type
        Parameters:
        type - The bean type
        singleton - The singleton bean
        qualifier - The bean qualifier
        inject - Whether the singleton should be injected (defaults to true)
        Returns:
        This bean context
      • createEnvironment

        @NonNull
        protected Environment createEnvironment​(@NonNull
                                                ApplicationContextConfiguration configuration)
        Creates the default environment for the given environment name.
        Parameters:
        configuration - The application context configuration
        Returns:
        The environment instance
      • createConversionService

        @NonNull
        protected io.micronaut.core.convert.ConversionService createConversionService()
        Creates the default conversion service.
        Returns:
        The conversion service
      • getConversionService

        @NonNull
        public io.micronaut.core.convert.ConversionService<?> getConversionService()
        Specified by:
        getConversionService in interface ApplicationContext
        Returns:
        The default conversion service
      • containsProperty

        public boolean containsProperty​(java.lang.String name)
        Specified by:
        containsProperty in interface io.micronaut.core.value.PropertyResolver
      • containsProperties

        public boolean containsProperties​(java.lang.String name)
        Specified by:
        containsProperties in interface io.micronaut.core.value.PropertyResolver
      • getProperty

        public <T> java.util.Optional<T> getProperty​(java.lang.String name,
                                                     io.micronaut.core.convert.ArgumentConversionContext<T> conversionContext)
        Specified by:
        getProperty in interface io.micronaut.core.value.PropertyResolver
      • getPropertyEntries

        @NonNull
        public java.util.Collection<java.lang.String> getPropertyEntries​(@NonNull
                                                                         java.lang.String name)
        Specified by:
        getPropertyEntries in interface io.micronaut.core.value.PropertyResolver
      • getProperties

        @NonNull
        public java.util.Map<java.lang.String,​java.lang.Object> getProperties​(@Nullable
                                                                                    java.lang.String name,
                                                                                    @Nullable
                                                                                    io.micronaut.core.naming.conventions.StringConvention keyFormat)
        Specified by:
        getProperties in interface io.micronaut.core.value.PropertyResolver
      • startEnvironment

        protected void startEnvironment()
        Start the environment.
      • findBeanCandidates

        protected <T> java.util.Collection<BeanDefinition<T>> findBeanCandidates​(BeanResolutionContext resolutionContext,
                                                                                 io.micronaut.core.type.Argument<T> beanType,
                                                                                 BeanDefinition<?> filter,
                                                                                 boolean filterProxied)
        Description copied from class: DefaultBeanContext
        Find bean candidates for the given type.
        Overrides:
        findBeanCandidates in class DefaultBeanContext
        Type Parameters:
        T - The bean generic type
        Parameters:
        resolutionContext - The current resolution context
        beanType - The bean type
        filter - A bean definition to filter out
        filterProxied - Whether to filter out bean proxy targets
        Returns:
        The candidates
      • findBeanCandidates

        protected <T> java.util.Collection<BeanDefinition<T>> findBeanCandidates​(BeanResolutionContext resolutionContext,
                                                                                 io.micronaut.core.type.Argument<T> beanType,
                                                                                 boolean filterProxied,
                                                                                 java.util.function.Predicate<BeanDefinition<T>> predicate)
        Description copied from class: DefaultBeanContext
        Find bean candidates for the given type.
        Overrides:
        findBeanCandidates in class DefaultBeanContext
        Type Parameters:
        T - The bean generic type
        Parameters:
        resolutionContext - The current resolution context
        beanType - The bean type
        filterProxied - Whether to filter out bean proxy targets
        predicate - The predicate to filter candidates
        Returns:
        The candidates
      • transformIterables

        protected <T> java.util.Collection<BeanDefinition<T>> transformIterables​(BeanResolutionContext resolutionContext,
                                                                                 java.util.Collection<BeanDefinition<T>> candidates,
                                                                                 boolean filterProxied)
        Description copied from class: DefaultBeanContext
        Method that transforms iterable candidates if possible.
        Overrides:
        transformIterables in class DefaultBeanContext
        Type Parameters:
        T - The bean type
        Parameters:
        resolutionContext - The resolution context
        candidates - The candidates.
        filterProxied - Whether to filter proxied.
        Returns:
        The candidates
      • findConcreteCandidate

        protected <T> BeanDefinition<T> findConcreteCandidate​(java.lang.Class<T> beanType,
                                                              Qualifier<T> qualifier,
                                                              java.util.Collection<BeanDefinition<T>> candidates)
        Description copied from class: DefaultBeanContext
        Fall back method to attempt to find a candidate for the given definitions.
        Overrides:
        findConcreteCandidate in class DefaultBeanContext
        Type Parameters:
        T - The generic time
        Parameters:
        beanType - The bean type
        qualifier - The qualifier
        candidates - The candidates, always more than 1
        Returns:
        The concrete bean definition
      • resolvePlaceholders

        public java.util.Optional<java.lang.String> resolvePlaceholders​(java.lang.String str)
        Description copied from interface: PropertyPlaceholderResolver
        Resolve the placeholders and return an Optional String if it was possible to resolve them.
        Specified by:
        resolvePlaceholders in interface PropertyPlaceholderResolver
        Parameters:
        str - The placeholder to resolve
        Returns:
        The optional string or Optional.empty() if resolution was not possible
      • initializeTypeConverters

        protected void initializeTypeConverters​(BeanContext beanContext)
        Parameters:
        beanContext - The bean context