【问题】如何在spring-aop中用@DeclareParents 扩展接口,调用被扩展类的对象

http://forum.springframework.org/showthread.php?t=59770
希望能够动态的给user类增加接口getContent,该接口直接返回User的toString方法的结果

据说基于spring aop达不到访问adviced object的目标,于是,将问题通过aspectj得到解决
package com.yyhy.java.search.compass;

import org.aspectj.lang.JoinPoint;

public aspect CompassAOP {

	declare parents: com.yyhy.java.GenericCoder.* extends DefaultCompassableImpl;
    declare parents: com.yyhy.java.Privilege.* extends DefaultCompassableImpl;
    declare parents: com.yyhy.hx.zcdfk.* extends DefaultCompassableImpl;
    declare parents: com.yyhy.hx.jgpmk.* extends DefaultCompassableImpl;
    declare parents: com.yyhy.log.* extends DefaultCompassableImpl;

public pointcut compass():execution(* *.getContent(..));
Object around():compass(){
   return thisJoinPoint.getThis().toString();
}
}

你可能感兴趣的:(java,spring,AOP,PHP)