Skip to content

Instantly share code, notes, and snippets.

@alanshaw
Created April 10, 2012 20:05
Show Gist options
  • Save alanshaw/2354103 to your computer and use it in GitHub Desktop.
Save alanshaw/2354103 to your computer and use it in GitHub Desktop.
Get the underlying object instance from a Spring proxy
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