aop切入点表达式, Pointcut is not well-formed: expecting 'name pattern' at character position 21 execution

**报错信息:

  • Pointcut is not well-formed: expecting ‘name pattern’ at character position 21
    execution(public .(…))**
    这种情况大多是切入点表达式错误,正确的切入点表达式格式为:
execution(方法修饰符 返回值 包名.类名.方法名(参数))

以以下代码为例

package com.swdeve.spring.ioc.service.impl;
import org.springframework.stereotype.Service;
import com.swdeve.spring.ioc.service.UserService;

@Service
public class UserServiceImpl implements UserService {

	public int add(int i, int j) {
		// TODO Auto-generated method stub
		return i + j;
	}	
	
}

完整切入表达式

execution(public int com.swdeve.spring.ioc.service.impl.UserServiceImpl.add(int,int))

模糊匹配,统一把修饰符的模糊匹配给去掉,因为面向切面编程的切人点的方法只能式public修饰的,干脆去掉,便于理解和记忆

  1. 任意返回值,任意包,任意类,任意方法,任意参数
execution(* *.*(..))

第一个“”号表示任意返回值;第二个“”号表示任意包,任意类;第三个“”号表示任意方法;…表示任意参数
注意:任意包和任意类的通配符合并为一个
号了

  1. 指定返回值,指定包,指定类,指定方法,任意参数
execution(int com.swdeve.spring.ioc.service.impl.UserServiceImpl.add(..))
  1. 指定返回值,指定包,指定类,任意方法,任意参数
execution(int com.swdeve.spring.ioc.service.impl.UserServiceImpl.*(..))
  1. 指定返回值,指定包,任意类,任意方法,任意参数
execution(int *.*(..))
  1. 指定返回值,指定包下的子包,任意类,任意方法,任意参数
execution(int com.swdeve..UserServiceImpl.*(..))

com.swdeve…后面的…表示指定包以及指定包下的子包

  1. 指定返回值,指定包下的子包,任意类,任意以指定字符开头的方法,任意参数
execution(int com.swdeve..*ServiceImpl.*(..))

自此,切入点表达式介绍完毕,需要注意一下几点

  1. 模糊切入点表达式最好把修饰符的通配符去掉,避免写出错误的切入点表达式
  2. *通配任意字符
  3. …统配当前包以及子包
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值