Package org.apache.logging.log4j.plugins
Annotation Interface Factory
Marks a method as a factory for supplying sources of instances of the method's return type.
Factory methods are comparable to bean factories from other dependency injection frameworks such as
@Bean
in the Spring Framework or @Provides
in the Guice framework. There are a few rules related to factory methods:
- Factory methods must be non-abstract methods of a bean class (static or not).
- If the bean class's scope is different from the provider bean, then it must be a larger scope.
- If factory methods return a nullable value, then it must be unscoped.
- Factory method return type must not be a type variable.
- Factory method return type may be parameterized only if it specifies actual types or a type variable for each parameter, the latter case also required to be unscoped.
- Classes may declare multiple factory methods to create different instance types or qualified instances.
- Factory methods are not inherited by subclasses.
- Classes annotated with
Configurable
can specify a static factory method instead of relying onInject
.