Created
April 10, 2012 20:05
-
-
Save alanshaw/2354103 to your computer and use it in GitHub Desktop.
Get the underlying object instance from a Spring proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getTargetObject[T](proxy: AnyRef, targetClass: Class[T]): T = { | |
if(AopUtils.isJdkDynamicProxy(proxy)) { | |
proxy.asInstanceOf[Advised].getTargetSource.getTarget.asInstanceOf[T] | |
} else { | |
proxy.asInstanceOf[T] // expected to be cglib proxy then, which is simply a specialized class | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment