正如在JDK代理的情況下的一個選項,你可以在運行時得到實際的bean:
MyBean proxy;
if(AopUtils.isJdkDynamicProxy(proxy)) {
MyBean actualInstance = (MyBean) ((Advised)proxy).getTargetSource().getTarget()
}
actualInstance.doSomethingSecured(); // no advice related to this method will be called
// so your security annotation will be ignored (transactions, cache, and everething that requires AOP too...)
但是從視圖具有手動代理方式的建築點看起來更小的誤差phrone(除非你絕對相信你不需要安全性和所有其他可能的方面)。
您可以使用泛型提高可讀性:
MyBean actualInstance = extractProxyTarget(proxy, proxy.getClass());
actualInstance.doSomethingSecured();