Created
May 7, 2015 17:49
Revisions
-
geowarin created this gist
May 7, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ package masterspringmvc4.utils; import org.springframework.aop.TargetSource; import org.springframework.aop.framework.Advised; import org.springframework.aop.support.AopUtils; public class ProxyUtils { public static <T> T getProxyTarget(Object proxy) { if (!AopUtils.isAopProxy(proxy)) { throw new IllegalStateException("Target must be a proxy"); } TargetSource targetSource = ((Advised) proxy).getTargetSource(); return getTarget(targetSource); } private static <T> T getTarget(TargetSource targetSource) { try { return (T) targetSource.getTarget(); } catch (Exception e) { throw new IllegalStateException(e); } } }