Class SpringInstantiator

java.lang.Object
com.vaadin.flow.di.DefaultInstantiator
com.vaadin.flow.spring.SpringInstantiator
All Implemented Interfaces:
Instantiator, Serializable

public class SpringInstantiator extends DefaultInstantiator
Default Spring instantiator that is used if no other instantiator has been registered. This implementation uses Spring beans.
Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • SpringInstantiator

      public SpringInstantiator(VaadinService service, org.springframework.context.ApplicationContext context)
      Creates a new spring instantiator instance.
      Parameters:
      service - the service to use
      context - the application context
  • Method Details

    • getServiceInitListeners

      public Stream<VaadinServiceInitListener> getServiceInitListeners()
      Description copied from interface: Instantiator
      Gets all service init listeners to use. In addition to listeners defined in some way native to a specific instantiator, it is also recommended to support the default ServiceLoader convention. This can be done by including the items from DefaultInstantiator.getServiceInitListeners() in the returned stream.
      Specified by:
      getServiceInitListeners in interface Instantiator
      Overrides:
      getServiceInitListeners in class DefaultInstantiator
      Returns:
      stream of service init listeners, not null
    • createComponent

      public <T extends Component> T createComponent(Class<T> componentClass)
      Description copied from interface: Instantiator
      Creates an instance of a component by its componentClass.
      Specified by:
      createComponent in interface Instantiator
      Overrides:
      createComponent in class DefaultInstantiator
      Type Parameters:
      T - the component type
      Parameters:
      componentClass - the instance type to create, not null
      Returns:
      the created instance, not null
    • getI18NProvider

      public I18NProvider getI18NProvider()
      Description copied from interface: Instantiator
      Get the I18NProvider if one has been defined.
      Specified by:
      getI18NProvider in interface Instantiator
      Overrides:
      getI18NProvider in class DefaultInstantiator
      Returns:
      I18NProvier instance
    • getOrCreate

      public <T> T getOrCreate(Class<T> type)
      Hands over an existing bean or tries to instantiate one with the following rules:
      • If exactly one bean is present in the context, it returns this bean.
      • If no bean is present, it tries to instantiate one.
      • If more than one bean is present, it tries to instantiate one but in case of a Bean instantiation exception this exception is catched and rethrown with a hint. Reason for this is, that users may expect it to "use" a bean but have multiple in the context. So the hint helps them find the problem.
      Specified by:
      getOrCreate in interface Instantiator
      Overrides:
      getOrCreate in class DefaultInstantiator
      Type Parameters:
      T - the type of the instance to create
      Parameters:
      type - the instance type to create, not null
      Returns:
      an instance of the given type
    • getApplicationClass

      public Class<?> getApplicationClass(Class<?> clazz)
      Description copied from interface: Instantiator
      Return the application-defined class for the given class: usually simply the given class, but the original class in case of a runtime generated subclass.
      Parameters:
      clazz - the class to check
      Returns:
      the user-defined class