Joinpoint VS ProceedingJoinPoint in AOP using aspectJ

If you use before,after-throwing,after-returning and after use Jointpoint.

@Pointcut("execution(* com.pointel.aop.test1.AopTest.beforeAspect(..))")  
public void adviceChild(){}  

public void beforeAdvicing(JoinPoint joinPoint /*,ProceedingJoinPoint pjp - used refer book marks of AOP*/){ 

    //Used to get the parameters of the method !
    Object[] arguments = joinPoint.getArgs();
    for (Object object : arguments) {
        System.out.println("List of parameters : " + object);

    System.out.println("Method name : " + joinPoint.getSignature().getName());"beforeAdvicing...........****************...........");"Method name : " + joinPoint.getSignature().getName());

If you use around use Proceedingjoinpoint .

An around advice is a special advice that can control when and if a method (or other join point) is executed. This is true for around advices only, so they require an argument of type ProceedingJoinPoint, whereas other advices just use a plain JoinPoint. A sample use case is to cache return values:

private SomeCache cache;

public Object cacheMethodReturn(ProceedingJoinPoint pjp){
    Object cached = cache.get(pjp.getArgs());
    if(cached != null) return cached; // method is never executed at all
        Object result = pjp.proceed();
        cache.put(pjp.getArgs(), result);
        return result;

In this code (using a non-existent cache technology to illustrate a point) the actual method is only called if the cache doesn’t return a result. This is the exact way the Spring EHCache Annotations project works, for example.

Another specialty of around advices is that they must have a return value, whereas other advice types must not have one.

use xml config

Note the pjp.proceed() will call the real method it arounds. 

		<!-- ***** Pointcut Definitions ***** -->
		<aop:pointcut id="allServicePointcut"
			expression="bean(*Service) or bean(*ServiceExternal) and not within(*)" />

		<!-- ***** Aspects ***** -->
			Aspect to handle transaction management for all internal and external
			service API's.
		<aop:aspect id="hibernateProxyRemovalAspect" ref="hibernateProxyRemovalAdvice" order="3">
			<aop:around pointcut-ref="allServicePointcut" method="removeProxy" />

	<bean id="hibernateProxyRemovalAdvice"
		<property name="hibernateProxyRemover" ref="hibernateProxyRemover" />

	<bean id="hibernateProxyRemover"
		class="" />
// Imports
import org.aspectj.lang.ProceedingJoinPoint;

 * Advice that removes hibernate proxy objects.
public class HibernateProxyRemovalAdvice
    private HibernateProxyRemover hibernateProxyRemover;

    public Object removeProxy(ProceedingJoinPoint pjp) throws Throwable
        return hibernateProxyRemover.removeProxy(pjp.proceed());

    public HibernateProxyRemover getHibernateProxyRemover()
        return hibernateProxyRemover;

    public void setHibernateProxyRemover(HibernateProxyRemover hibernateProxyRemover)
        this.hibernateProxyRemover = hibernateProxyRemover;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s