Annotation Interface Wrapper


@Retention(CLASS) @Target(TYPE) public @interface Wrapper

Used in conjunction with @Bean to indicate a wrapper bean.

A wrapper bean should be used to create beans using legacy code which can't be annotated with @Bean, it allows to delegate the actual instantiation, initialization and destruction to a wrapper class. As a result a wrapper implementing the Supplier interface.

A wrapper bean follows the same rules as regular beans: dependencies are injected into sockets defined on the wrapper class, initialization methods are invoked after dependency injection and destroy methods before bean removal on the wrapper instance. However the instance actually exposed is returned by the Supplier.get() method. There is no requirement that a new or distinct result be returned each time the wrapper is invoked but when initialization or destruction methods are specified, the wrapper must naturally create and always return a single wrapped instance which can then be initialized and destroyed by the wrapper. In that particular case, WeakReference should be used in the wrapper to hold the actual bean instance to prevent memory leaks that might arise in certain situations.

Since:
1.0
Author:
Jeremy Kuhn
See Also: