Class ConfigurationBasedInstanceCreator

    • Method Detail

      • create

        public static <T> T create​(Class<T> configurableClass,
                                   Method method)
        Creates a new instance of a class, possibly with a supplied ConfigurationProvider.

        Searches for a ConfigurationSource of with the correct ConfigurationSource.configurable() on the method. If such a source is found, the instance is created using the supplied configuration, otherwise a no-args constructor is used. Consequently, the configurableClass should always have a no-args constructor.

        Type Parameters:
        T - the type of the instance created by the method
        Parameters:
        configurableClass - the class for which an instance should be created, possibly with a configuration supplied by a ConfigurationProvider on the method. Must not be null
        method - the method possibly annotated with ConfigurationSource. Must not be null
        Returns:
        the instance created with a configuration if one was provided. Never null