Spring 【Aspectj】【注解】引入通知 ------ 为【目标对象】添加,【新接口】及【实现】

1.新接口

/**
 * 访问身高接口
 */
public interface IHeight {

    public void setHeight(Integer height);
    
    public Integer getHeight();
}

 

2.新接口的实现类

/**
 * 身高接口的实现
 */
public class HeightImpl implements IHeight{

    private Integer height;

    @Override
    public void setHeight(Integer height) {
        this.height = height;
    }

    @Override
    public Integer getHeight() {
        return height;
    }
}

 

3.切片类中 @DeclareParents 修饰 新接口持有对象。

/**
 *    观众
 */
@Aspect   //切片
public class Audience {

    @DeclareParents(value="aspectj.Singer",           // 目标对象
                    defaultImpl=HeightImpl.class)      // 新增接口的实现类
    private IHeight height;                              // 新增的接口  <=== 实现类
    
    //....  
}    

 

 

posted @ 2013-12-16 23:48  聆听自由  阅读(278)  评论(0编辑  收藏  举报