java 包内_java – 包中所有方法的AOP

我是第一次使用AOP.

我写了下面的AOP代码,当我用它来拦截一个特定的方法时它工作正常.

有人可以指导我 – 如何设置它来拦截某个包中的所有方法(com.test.model)?

基本上如何设置appcontext.xml.

另外,在调用每个方法之前,我是否需要执行类似下面的操作?

AopClass aoptest = (AopClass) _applicationContext.getBean("AopClass");

aoptest.addCustomerAround("dummy");

有人可以帮忙吗?

如果需要更多解释,请告诉我.

以下是我的代码:

接口:

package com.test.model;

import org.springframework.beans.factory.annotation.Autowired;

public interface AopInterface {

@Autowired

void addCustomerAround(String name);

}

类:

package com.test.model;

import com.test.model.AopInterface;

import org.springframework.stereotype.Component;

import org.springframework.beans.factory.annotation.Autowired;

@Component

public class AopClass implements AopInterface {

public void addCustomerAround(String name){

System.out.println("addCustomerAround() is running, args : " + name);

}

}

AOP:

package com.test.model;

import java.util.Arrays;

import org.aspectj.lang.ProceedingJoinPoint;

import org.aspectj.lang.annotation.Around;

import org.aspectj.lang.annotation.Aspect;

import org.aspectj.lang.annotation.Pointcut;

@Aspect

public class TestAdvice{

@Around("execution(* com.test.model.AopInterface.addCustomerAround(..))")

public void testAdvice(ProceedingJoinPoint joinPoint) throws Throwable {

System.out.println("testAdvice() is running!");

}

}

appcontext:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值