**报错信息:
- 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修饰的,干脆去掉,便于理解和记忆
- 任意返回值,任意包,任意类,任意方法,任意参数
execution(* *.*(..))
第一个“”号表示任意返回值;第二个“”号表示任意包,任意类;第三个“”号表示任意方法;…表示任意参数
注意:任意包和任意类的通配符合并为一个号了
- 指定返回值,指定包,指定类,指定方法,任意参数
execution(int com.swdeve.spring.ioc.service.impl.UserServiceImpl.add(..))
- 指定返回值,指定包,指定类,任意方法,任意参数
execution(int com.swdeve.spring.ioc.service.impl.UserServiceImpl.*(..))
- 指定返回值,指定包,任意类,任意方法,任意参数
execution(int *.*(..))
- 指定返回值,指定包下的子包,任意类,任意方法,任意参数
execution(int com.swdeve..UserServiceImpl.*(..))
com.swdeve…后面的…表示指定包以及指定包下的子包
- 指定返回值,指定包下的子包,任意类,任意以指定字符开头的方法,任意参数
execution(int com.swdeve..*ServiceImpl.*(..))
自此,切入点表达式介绍完毕,需要注意一下几点
- 模糊切入点表达式最好把修饰符的通配符去掉,避免写出错误的切入点表达式
- *通配任意字符
- …统配当前包以及子包