Spring之Introductions(简介)应用

这里写图片描述

这里写图片描述

解释说明:
types-matching中匹配到的对象,相当于会给此类添加一个父类,其中的该父类的接口为implement-interface,实现类为default-impl,这样得到bean的对象后强转为该接口对象
<aop:config>

        <aop:aspect id="moocAspectAOP" ref="moocAspect">
        <aop:declare-parents types-matching="com.wuyonghu.spring2.*(+)" implement-interface="com.wuyonghu.spring2.Fit" default-impl="com.wuyonghu.spring2.FitImpl"/>
        </aop:aspect> 
    </aop:config>

接口:

public interface Fit {

    void filter();
}

接口实现类:

public class FitImpl implements Fit {

    public void filter() {
        System.out.println("這是FitImpl中的filter方法執行了");
    }

}

业务类:

@Service
public class AspectBiz {

}

测试类:

@Test
    public void testFit() {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        //此时得到aspectBiz对象,且转换为Fit后,就可以调用filter方法了
        Fit fit =(Fit) context.getBean("aspectBiz");
        fit.filter();
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值