Pointcut is not well-formed: expecting 'identifier' at character position 0 ^ || Pointcut is not well-formed: expecting ')' at character position 11 ^
错误提示:
解决方法1:指定execution
在执行目标方法之前指定execution
解决方法2:可能是execution写错了。请仔细检查。
其他——execution参数设置(带问好的可以不配置,否则必须配置):
execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern)throws-pattern?)
returning type pattern,name pattern, and parameters pattern是必须的.
modifiers-pattern:可以是public等。。
ret-type-pattern:返回值类型;可以为*表示任何返回值,全路径的类名等.
name-pattern()方法名和参数
throws-pattern异常。。。
例如:
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
//把这个类声明为一个切面,需要把该类放入到IOC容器中
@Aspect
@Component
public class LoggingAspect {
//声明该方法是一个前置通知:在目标方法之前执行
@Before("execution(public int lixiuming.spring.aop.impl.ArithmeticCaculator.add(int, int) )")
public void beforeMethod(){
System.out.println("the method begins with");
}
}
接口:
import org.springframework.stereotype.Service;
@Service
public interface ArithmeticCaculator {
int add(int i,int j);
int sub(int i,int j);
int mul(int i,int j);
int div(int i,int j);
}
测试方法:
public class Main {
public static void main(String[] args) {
ApplicationContext cxt = new ClassPathXmlApplicationContext("ApplicationContext.xml");
ArithmeticCaculator arithmeticCaculator = cxt.getBean(ArithmeticCaculator.class);
int result = arithmeticCaculator.add(3, 6);
System.out.println("result:"+result);
}
}
实现方法:
import org.springframework.stereotype.Component;
@Component
public class ArithmeticCaculatorImpl2 implements ArithmeticCaculator {
@Override
public int add(int i, int j) {
int result = i+j;
return result;
}
@Override
public int sub(int i, int j) {
int result = i-j;
return result;
}
@Override
public int mul(int i, int j) {
int result = i*j;
return result;
}
@Override
public int div(int i, int j) {
int result = i/j;
return result;
}
}