Customizing Proxy Generation
The default behaviour of the Around annotation is to generate a proxy at compile time that is a subclass of the proxied class. In other words, in the previous example a compile-time subclass of the NotNullExample
class will be produced where proxied methods are decorated with interceptor handling, and the original behaviour is invoked via a call to super
.
This behaviour is more efficient as only one instance of the bean is required, however depending on the use case you may wish to alter this behaviour. The @Around
annotation supports various attributes that allow you to alter this behaviour, including:
proxyTarget
(defaults tofalse
) - If set totrue
, instead of a subclass that callssuper
, the proxy delegates to the original bean instancehotswap
(defaults tofalse
) - Same asproxyTarget=true
, but in addition the proxy implements HotSwappableInterceptedProxy which wraps each method call in aReentrantReadWriteLock
and allows swapping the target instance at runtime.lazy
(defaults tofalse
) - By default Micronaut eagerly initializes the proxy target when the proxy is created. If set totrue
the proxy target is instead resolved lazily for each method call.