Interface ApplicationContext

    • Method Detail

      • getConversionService

        @NonNull
        io.micronaut.core.convert.ConversionService<?> getConversionService()
        Returns:
        The default conversion service
      • getEnvironment

        @NonNull
        Environment getEnvironment()
        Returns:
        The application environment
      • registerSingleton

        @NonNull
        <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 BeanContext
        Specified by:
        registerSingleton in interface BeanDefinitionRegistry
        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
      • registerSingleton

        @NonNull
        default <T> ApplicationContext registerSingleton​(@NonNull
                                                         java.lang.Class<T> type,
                                                         @NonNull
                                                         T singleton,
                                                         @Nullable
                                                         Qualifier<T> qualifier)
        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 BeanContext
        Specified by:
        registerSingleton in interface BeanDefinitionRegistry
        Type Parameters:
        T - The concrete type
        Parameters:
        type - The bean type
        singleton - The singleton bean
        qualifier - The bean qualifier
        Returns:
        This bean context
      • registerSingleton

        @NonNull
        default <T> ApplicationContext registerSingleton​(@NonNull
                                                         java.lang.Class<T> type,
                                                         @NonNull
                                                         T singleton)
        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 BeanContext
        Specified by:
        registerSingleton in interface BeanDefinitionRegistry
        Type Parameters:
        T - The concrete type
        Parameters:
        type - the bean type
        singleton - The singleton bean
        Returns:
        This bean context
      • registerSingleton

        @NonNull
        default ApplicationContext registerSingleton​(@NonNull
                                                     java.lang.Object singleton,
                                                     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 BeanContext
        Specified by:
        registerSingleton in interface BeanDefinitionRegistry
        Parameters:
        singleton - The singleton bean
        inject - Whether the singleton should be injected (defaults to true)
        Returns:
        This bean context
      • environment

        @NonNull
        default ApplicationContext environment​(@NonNull
                                               java.util.function.Consumer<Environment> consumer)
        Allow configuration the Environment.
        Parameters:
        consumer - The consumer
        Returns:
        This context
      • registerSingleton

        @NonNull
        default ApplicationContext registerSingleton​(@NonNull
                                                     java.lang.Object singleton)
        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 BeanContext
        Specified by:
        registerSingleton in interface BeanDefinitionRegistry
        Parameters:
        singleton - The singleton bean
        Returns:
        This bean context
      • run

        @NonNull
        static ApplicationContext run​(@NonNull
                                      java.util.Map<java.lang.String,​java.lang.Object> properties,
                                      @NonNull
                                      java.lang.String... environments)
        Run the ApplicationContext with the given type. Returning an instance of the type. Note this method should not be used. If the ApplicationContext requires graceful shutdown unless the returned bean takes responsibility for shutting down the context.
        Parameters:
        properties - Additional properties
        environments - The environment names
        Returns:
        The running ApplicationContext
      • run

        @NonNull
        static ApplicationContext run​(@NonNull
                                      PropertySource properties,
                                      @NonNull
                                      java.lang.String... environments)
        Run the ApplicationContext with the given type. Returning an instance of the type. Note this method should not be used. If the ApplicationContext requires graceful shutdown unless the returned bean takes responsibility for shutting down the context.
        Parameters:
        properties - Additional properties
        environments - The environment names
        Returns:
        The running ApplicationContext
      • run

        @NonNull
        static <T extends java.lang.AutoCloseable> T run​(@NonNull
                                                         java.lang.Class<T> type,
                                                         @NonNull
                                                         java.lang.String... environments)
        Run the ApplicationContext with the given type. Returning an instance of the type. Note this method should not be used. If the ApplicationContext requires graceful shutdown unless the returned bean takes responsibility for shutting down the context.
        Type Parameters:
        T - The type
        Parameters:
        type - The type of the bean to run
        environments - The environments to use
        Returns:
        The running bean
      • run

        @NonNull
        static <T extends java.lang.AutoCloseable> T run​(@NonNull
                                                         java.lang.Class<T> type,
                                                         @NonNull
                                                         java.util.Map<java.lang.String,​java.lang.Object> properties,
                                                         @NonNull
                                                         java.lang.String... environments)
        Run the ApplicationContext with the given type. Returning an instance of the type. Note this method should not be used. If the ApplicationContext requires graceful shutdown unless the returned bean takes responsibility for shutting down the context.
        Type Parameters:
        T - The type
        Parameters:
        type - The type of the bean to run
        properties - Additional properties
        environments - The environment names
        Returns:
        The running bean
      • run

        @NonNull
        static <T extends java.lang.AutoCloseable> T run​(@NonNull
                                                         java.lang.Class<T> type,
                                                         @NonNull
                                                         PropertySource propertySource,
                                                         @NonNull
                                                         java.lang.String... environments)
        Run the ApplicationContext with the given type. Returning an instance of the type. Note this method should not be used. If the ApplicationContext requires graceful shutdown unless the returned bean takes responsibility for shutting down the context.
        Type Parameters:
        T - The type
        Parameters:
        type - The environment to use
        propertySource - Additional properties
        environments - The environment names
        Returns:
        The running BeanContext
      • builder

        @NonNull
        static ApplicationContextBuilder builder​(@NonNull
                                                 java.lang.String... environments)
        Parameters:
        environments - The environments to use
        Returns:
        The application context builder
      • builder

        @NonNull
        static ApplicationContextBuilder builder​(@NonNull
                                                 java.util.Map<java.lang.String,​java.lang.Object> properties,
                                                 @NonNull
                                                 java.lang.String... environments)
        Parameters:
        properties - The properties
        environments - The environments to use
        Returns:
        The application context builder
      • builder

        @NonNull
        static ApplicationContextBuilder builder​(java.lang.ClassLoader classLoader)
        Parameters:
        classLoader - The class loader to use
        Returns:
        The application context builder
      • run

        @NonNull
        static ApplicationContext run​(@NonNull
                                      java.lang.ClassLoader classLoader,
                                      @NonNull
                                      java.lang.String... environments)
        Run the BeanContext. This method will instantiate a new BeanContext and call start()
        Parameters:
        classLoader - The classloader to use
        environments - The environments to use
        Returns:
        The running ApplicationContext
      • builder

        @NonNull
        static ApplicationContextBuilder builder​(@NonNull
                                                 java.lang.ClassLoader classLoader,
                                                 @NonNull
                                                 java.lang.String... environments)
        Parameters:
        classLoader - The classloader to use
        environments - The environment to use
        Returns:
        The application context builder
      • builder

        @NonNull
        static ApplicationContextBuilder builder​(@NonNull
                                                 java.lang.Class mainClass,
                                                 @NonNull
                                                 java.lang.String... environments)
        Parameters:
        mainClass - The main class of the application
        environments - The environment to use
        Returns:
        The application context builder