Package com.vaadin.flow.spring
Class SpringInstantiator
java.lang.Object
com.vaadin.flow.di.DefaultInstantiator
com.vaadin.flow.spring.SpringInstantiator
- All Implemented Interfaces:
Instantiator,Serializable
Default Spring instantiator that is used if no other instantiator has been
registered. This implementation uses Spring beans.
- Author:
- Vaadin Ltd
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSpringInstantiator(VaadinService service, org.springframework.context.ApplicationContext context) Creates a new spring instantiator instance. -
Method Summary
Modifier and TypeMethodDescription<T extends Component>
TcreateComponent(Class<T> componentClass) Creates an instance of a component by itscomponentClass.Get the I18NProvider if one has been defined.<T> TgetOrCreate(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.Gets all service init listeners to use.Methods inherited from class com.vaadin.flow.di.DefaultInstantiator
getServiceLoaderListenersMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.di.Instantiator
createRouteTarget, getDependencyFilters, getIndexHtmlRequestListeners
-
Constructor Details
-
SpringInstantiator
public SpringInstantiator(VaadinService service, org.springframework.context.ApplicationContext context) Creates a new spring instantiator instance.- Parameters:
service- the service to usecontext- the application context
-
-
Method Details
-
getServiceInitListeners
Description copied from interface:InstantiatorGets 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 defaultServiceLoaderconvention. This can be done by including the items fromDefaultInstantiator.getServiceInitListeners()in the returned stream.- Specified by:
getServiceInitListenersin interfaceInstantiator- Overrides:
getServiceInitListenersin classDefaultInstantiator- Returns:
- stream of service init listeners, not
null
-
createComponent
Description copied from interface:InstantiatorCreates an instance of a component by itscomponentClass.- Specified by:
createComponentin interfaceInstantiator- Overrides:
createComponentin classDefaultInstantiator- Type Parameters:
T- the component type- Parameters:
componentClass- the instance type to create, notnull- Returns:
- the created instance, not
null
-
getI18NProvider
Description copied from interface:InstantiatorGet the I18NProvider if one has been defined.- Specified by:
getI18NProviderin interfaceInstantiator- Overrides:
getI18NProviderin classDefaultInstantiator- Returns:
- I18NProvier instance
-
getOrCreate
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:
getOrCreatein interfaceInstantiator- Overrides:
getOrCreatein classDefaultInstantiator- Type Parameters:
T- the type of the instance to create- Parameters:
type- the instance type to create, notnull- Returns:
- an instance of the given type
-