您当前的位置: 首页 >  Java

qq_34412985

暂无认证

  • 0浏览

    0关注

    1061博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

nested exception is java.lang.IllegalArgumentException: error at ::0 formal

qq_34412985 发布时间:2020-05-20 17:43:35 ,浏览量:0

使用aop报错:去掉参数。。。

在使用声明方式的AOP编程中,遇到以下问题,解决方法如下:

(1)error at ::0 formal unbound in pointcut

解决方法:去掉函数通知函数中的参数,比如:将

@Before("execution(public void com.bjsxt.dao.impl.UserDAOImpl.*(..))")

    public void beforeMethod(Method method){

       System.out.println("method before");

    }

改为

@Before("execution(public void com.bjsxt.dao.impl.UserDAOImpl.*(..))")

    public void beforeMethod(){

       System.out.println("method before");

    }

情况二:

原写法:

@Before("@annotation(org.haha.web.annotation.BrowAuth) public void beforeExec(HttpServletRequest request) {

    ......

}

会报以下错误:

0 formal unbound in pointcut

原因是应该用args指明参数,改成以下就可以了:

@Before("@annotation(org.haha.web.annotation.BrowAuth) && (args(request,..) || args(..,request))") public void beforeExec(HttpServletRequest request) {

    ......

}

方法中未带参数,本bug 非此原因

(2)可能原因(我的猜测,未确认)

  使用了AOP 之后(spring),实现注解是采用代理的方式,而代理有两种jdk自带代理和 cglib,而在springmvc 中直接使用自动注解的时候,没有使用这一层代理。接口、接口的实现类,其注解的命名方式不一致,造成了自动注入的时候,代理不知道该选择哪一个类……

  可解决方法:一、使用AOP注解,将原有的业务上的接口、接口实现类的命名改统一。假设接口为 IUserDao,实现类为 UserDaoImpl ,自动注入的时候写成  IUserDao userDaoImpl  (原因:不清楚)

    方法二、不要使用AOP注解,在xml 中配置需要的AOP 方式,如下:自定义LoggingInterceptor 中有个around 方法   

  
		
			
			
			
		
	
关注
打赏
1653291990
查看更多评论
立即登录/注册

微信扫码登录

0.6518s