AOP
AOP extension allows you to wrap beans' methods with additional functionality, such as logging or transaction management. It is similar to Aspect-Oriented Programming (AOP) in other frameworks.
Current extensions:
sigewine-aop-sentry
: Provides integration with Sentry for automatic transaction handling.
Usage
To use the AOP functionality, you need to add the sigewine-aop
module to your project. Please refer to main Sigewine documentation for more information.
Method Wrappers
Method wrappers are used to wrap methods of beans with additional functionality. They are defined by implementing the MethodWrapper
abstract class and an annotation. The annotation is used to mark the methods that should be wrapped. You may also annotate the whole class to wrap all methods in it.
Their methods are invoked before and after the original method invocation. Please note that the after method invocation occurs even if the original method throws an exception.
Defining a Method Wrapper
As you can see, the afterInvocation
contains Optional<Object> optionalResult
and Optional<Throwable> optionalThrowable
. These optionals will be filled with the result of the method invocation and any exception thrown by it, respectively. You can use these to handle the result or exception in your wrapper.
Registering Method Wrappers
You may register your method wrappers in the AopConstellation
instance. This should be done before scanning for beans as the wrappers will be applied to the beans during the scanning process.
Example of registering
Marking Methods for Wrapping
Simply annotate a method or whole class with the annotation you defined in the method wrapper. For example: