Example usage for org.springframework.aop.aspectj MethodInvocationProceedingJoinPoint getTarget

List of usage examples for org.springframework.aop.aspectj MethodInvocationProceedingJoinPoint getTarget

Introduction

In this page you can find the example usage for org.springframework.aop.aspectj MethodInvocationProceedingJoinPoint getTarget.

Prototype

@Override
@Nullable
public Object getTarget() 

Source Link

Document

Returns the Spring AOP target.

Usage

From source file:org.geppetto.persistence.db.BundleClassLoaderAspect.java

public Object setClassLoader(MethodInvocationProceedingJoinPoint pjp) throws Throwable {
    // Save a reference to the classloader of the caller
    ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
    // Get a reference to the classloader of the owning bundle
    ClassLoader serviceLoader = pjp.getTarget().getClass().getClassLoader();
    // Set the class loader of the current thread to the class loader of the
    // owner of the bundle
    Thread.currentThread().setContextClassLoader(serviceLoader);

    Object returnValue = null;//from   w  w  w. j  av a2 s  .co m

    try {
        // Make the actual call to the method.
        returnValue = pjp.proceed();
    } finally {
        // Reset the classloader of this Thread to the original
        // classloader of the method invoker.
        Thread.currentThread().setContextClassLoader(oldLoader);
    }

    return returnValue;
}