for example by reviewing this code
@Aspect
class CommandExecuteInterceptor implements ApplicationContextAware {
private ApplicationContext context;
what does @aspect mean, to use it, when to use it?
for example by reviewing this code
@Aspect
class CommandExecuteInterceptor implements ApplicationContextAware {
private ApplicationContext context;
what does @aspect mean, to use it, when to use it?
This has to do with the paradigm of Aspects-Oriented Programming (AOP), I briefly commented:
Aspect-Oriented Programming (AOP) is a programming paradigm that tries to formalize and represent in a concise way the elements that are transversal to the whole system. How is this? a common example is the control of permission to execute certain methods in a class.
public class ObjetoDeNegocio {
public void metodoDeNegocio1() throws SinPermisoException {
validarPermisos();
//resto del código
...
}
public void metodoDeNegocio2() throws SinPermisoException {
validaPermisos();
//resto del código
...
}
}
In AOP, the elements that are transversal to the structure of the system and can be modularized thanks to the constructions that the paradigm contributes are called aspects (aspects).
An aspect (aspect) is a set of advices. Following the AspectJ syntax, the aspects are represented as Java classes, marked with the annotation @Aspect. In Spring, in addition, an aspect must be a bean, so you have to write it down as such
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class EjemploDeAspecto {
//aquí vendrían los advices...
}