【发布时间】:2019-08-23 14:56:49
【问题描述】:
我正在使用 Java 8、spring 4.3 和 AspectJ 1.8.9。为什么我收到以下代码的以下错误。如果我在没有切入点的情况下使用 @Before("com.beans.Student.addCustomer()") 我会在 0 处收到此错误,找不到引用的切入点。将@Before 与切入点一起使用时,我没有收到错误消息。
豆子:
@Aspect
public class Beforeaspect {
/*
* @Pointcut("execution(* com.beans.Student.addCustomer(..))") public void
* log(){
* }
*/
// @Before("log()")
@Before("com.beans.Student.addCustomer()")
public void logBefore(JoinPoint jp) {
System.out.println("logbefore");
System.out.println("method " + jp.getSignature().getName());
}
}
学生:
package com.beans;
public class Student implements Studentimpl {
public void addCustomer() {
System.out.println("addcustomer");
}
public String addCustomername(String stud) {
System.out.println("addcustomername");
return "hello";
}
}
Spring xml 文件:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<aop:aspectj-autoproxy />
<bean id="stud" class="com.beans.Student" />
<bean class="com.beans.Beforeaspect" />
</beans>
【问题讨论】:
标签: java spring spring-boot aop spring-aop