Class BeanCreator<T>
- Type Parameters:
T- The bean type being created.
Uses a BeanStore to find available ways to construct beans via injection of beans from the store.
This class is instantiated through the following method:
Example:
Looks for the following methods for creating a bean:
- Looks for a singleton no-arg method of the form:
public static MyClassgetInstance ();- Deprecated and
@BeanIgnore-annotatedmethods are ignored.
- Deprecated and
- Looks for a static creator method of the form:
public static MyClasscreate (<args> );- All arguments except
OptionalandListparameters must have beans available in the store. - If multiple methods are found, the one with the most matching parameters is used.
- Deprecated and
@BeanIgnore-annotatedmethods are ignored.
- All arguments except
- Looks for a public constructor of the form:
public MyClass(<args> );- All arguments except
OptionalandListparameters must have beans available in the store. - If multiple methods are found, the one with the most matching parameters is used.
- Deprecated and
@BeanIgnore-annotatedmethods are ignored.
- All arguments except
- Looks for a protected constructor of the form:
protected MyClass(<args> );- All arguments except
OptionalandListparameters must have beans available in the store. - If multiple methods are found, the one with the most matching parameters is used.
- Deprecated and
@BeanIgnore-annotatedmethods are ignored.
- All arguments except
- Looks for a static no-arg create method that returns a builder object that can be passed in to a protected constructor.
public static MyClass.Buildercreate ();protected MyClass(MyClass.Builderbuilder );- Deprecated and
@BeanIgnore-annotatedmethods are ignored.
- Deprecated and
Notes:
- The
builder(Class,Object)method can be used to set an existing initialized builder object to pass to a constructor. - An existing initialized builder can be set using the
builder(Class,Object)method.
See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T2> BeanCreator<T>Adds an argument to this creator.<B> BeanCreator<T>Specifies a builder object for the bean type.execute()Allows you to specify a specific instance for the build method to return.static <T> BeanCreator<T>Shortcut for callingBeanStore.INSTANCE.createBean(beanType) .Same asrun()but returns the alternate value if a method of creation could not be found.run()Creates the bean.silent()Suppresses throwing ofExecutableExceptionsfrom therun()method when a form of creation cannot be found.supplier()Converts this creator into a supplier.Allows you to specify a subclass of the specified bean type to create.Allows you to specify a subclass of the specified bean type to create.
-
Constructor Details
-
BeanCreator
Constructor.- Parameters:
type- The bean type being created.store- The bean store creating this creator.
-
-
Method Details
-
of
Shortcut for callingBeanStore.INSTANCE.createBean(beanType) .- Type Parameters:
T- The bean type to create.- Parameters:
beanType- The bean type to create.- Returns:
- A new creator.
-
arg
Adds an argument to this creator.- Type Parameters:
T2- The parameter type.- Parameters:
beanType- The parameter type.bean- The parameter value.- Returns:
- This object.
-
builder
Specifies a builder object for the bean type.Notes:
- When specified, we don't look for a static creator method.
- Type Parameters:
B- The class type of the builder.- Parameters:
type- The class type of the builder.value- The value for this setting.- Returns:
- This object.
-
execute
- Returns:
- A new bean wrapped in an
Optional.
-
impl
Allows you to specify a specific instance for the build method to return.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
orElse
Same asrun()but returns the alternate value if a method of creation could not be found.- Parameters:
other- The other bean to use.- Returns:
- Either the created or other bean.
-
run
Creates the bean.- Returns:
- A new bean.
- Throws:
ExecutableException- if bean could not be created andsilent()was not enabled.
-
silent
Suppresses throwing ofExecutableExceptionsfrom therun()method when a form of creation cannot be found.- Returns:
- This object.
-
supplier
Converts this creator into a supplier.- Returns:
- A supplier that returns the results of the
run()method.
-
type
Allows you to specify a subclass of the specified bean type to create.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
type
Allows you to specify a subclass of the specified bean type to create.- Parameters:
value- The value for this setting.- Returns:
- This object.
-