Customizing Proxy Generation
The default behaviour of the Around annotation is to generate a proxy at compile time that is a subclass of the class being proxied. In other words, in the previous example a compile time subclass of the NotNullExample
class will be produced where methods that are proxied 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 are trying to implement you may wish to alter this behaviour and 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 will delegate to the original bean instancehotswap
(defaults tofalse
) - Same asproxyTarget=true
, but in addition the proxy will implement HotSwappableInterceptedProxy which wraps each method call in aReentrantReadWriteLock
and allows swapping the target instance at runtime.lazy
(defaults tofalse
) - By default Micronaut will eagerly intialize the proxy target when the proxy is created. If set totrue
the proxy target will instead be resolved lazily for each method call.