Aspects of programming means cross cutting concerns.
Note: we should use @EnableAspectJAutoProxy before @Configuration file.
<aop:aspectj-autoproxy>
in xml config file
Aspect: class which define pointcuts and advices
Advice: behaviour that executes at join point.
Join point : argument value of the aop method
Pointcut: expression language of AOP that matches join points, enable reuse of pointcut
@Aspect - declare class
Advice represents an action taken by an aspect at a particular join point.
void afterReturningMethod(Object result)
void afterThrowingMethod(Exception ex)
void aroundMethod(ProceedingJoinPoint jp)
@Aspect
@Component
public class AOPsample {
@Around("execution(public void org.controller.display())")
void aroundMethod(ProceedingJoinPoint jp){
Object[] args = jp.getArgs();
sysout("before execution of function");
Object result = jp.proceed(args); //method executes
sysout("after execution of function");
}
}
expression language of AOP that matches join points, enable reuse of pointcut
@Pointcut("execution(public void org.controller.display())")
void reuseMethod(){}
@Before("reuseMethod()")
void methodName2(){
}
@Before("reuseMethod()")
void methodName3(){
}
gives order of execution to aspect class
public void display(JointPoint jointPoint){
MethodSignature methodSig = (MethodSignature) jointPoint.getSignature();
Object[] args = joinPoint.getArgs(); //get arguements
}
private Logger log = Logger.getLogger(getClass().getName());
log.info("log message");
log.fatal("log message");
log.debug("log message");
log.error("log message");
log.warn("log message");
log.trace("log message");
public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer {
}
@Configuration
@EnableWebSecurity
public class DemoSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("john").password("secret123").roles("EMPLOYEE");
auth.inMemoryAuthentication().withUser("mary").password("secret123").roles("MANAGER");
}
}