Interface BeanFactory<T>

Type Parameters:
T - The type of bean this factory creates.
All Known Implementing Classes:
BeanFactory.Void
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface BeanFactory<T>
A universal factory interface used with @Marshalled(factory=X.class) for any bean type the framework needs to instantiate.

This interface provides a single DI hook for all framework-managed classes including BeanConsumer, BeanSupplier, BeanChannel, ObjectSwap subclasses, and any ordinary bean class parsed from JSON/XML/etc.

When a class annotated with @Marshalled(factory=MyFactory.class) needs to be instantiated, the framework resolves the factory as follows:

  1. Look up the factory class in the BeanStore (e.g. Spring ApplicationContext)
  2. If not found in the store, attempt to instantiate the factory directly via no-arg constructor or getInstance() static method
  3. If both fail, throw IllegalArgumentException
Example (Spring integration):

// Spring singleton factory that creates per-request ItemChannel instances @Component public class ItemChannelFactory implements BeanFactory<ItemChannel> { @Autowired DataSource ds; @Override public ItemChannel create() { return new ItemChannel(ds); } } // The target class declares which factory creates it @Marshalled(factory=ItemChannelFactory.class) public class ItemChannel implements BeanChannel<Item> { ... }

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final class 
    Sentinel class used as the default value for @BeanType(factory=...) and @BeanProp(factory=...) when no factory is specified.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new instance of the bean.
  • Method Details

    • create

      T create() throws Exception
      Creates a new instance of the bean.
      Returns:
      A new bean instance.
      Throws:
      Exception - If the bean cannot be created.