Java 0 can'处的弹簧AOP错误;找不到引用的切入点
我正在使用Java8、Spring4.3和AspectJ1.8.9。为什么我得到下面的代码下面的错误。如果我在没有切入点的情况下使用@Before(“com.beans.Student.addCustomer()”),我将在0处遇到此错误,无法找到引用的切入点。在使用@Before和切入点时,我没有得到错误 豆子:Java 0 can'处的弹簧AOP错误;找不到引用的切入点,java,spring,spring-boot,aop,spring-aop,Java,Spring,Spring Boot,Aop,Spring Aop,我正在使用Java8、Spring4.3和AspectJ1.8.9。为什么我得到下面的代码下面的错误。如果我在没有切入点的情况下使用@Before(“com.beans.Student.addCustomer()”),我将在0处遇到此错误,无法找到引用的切入点。在使用@Before和切入点时,我没有得到错误 豆子: @Aspect public class Beforeaspect { /* * @Pointcut("execution(* com.beans.Student
@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>
方法执行时使用了错误的语法。您的注释应该是:
@Before("execution(* com.beans.Student.addCustomer(..))")
public void logBefore(JoinPoint jp) {
System.out.println("logbefore");
System.out.println("method " + jp.getSignature().getName());
}
或者使用XML Bean:
<aop:aspectj-autoproxy />
<bean id="logAspect" class="nch.spring.aop.aspectj.LoggingAspect" />
<aop:config>
<aop:aspect id="aspectLoggging" ref="logAspect">
<aop:pointcut id="pointCutBefore" expression="execution(* com.beans.Student.addCustomer(..)))" />
<aop:before method="logBefore" pointcut-ref="pointCutBefore" />
<aop:aspect/>
<aop:config>
方法执行时使用了错误的语法。您的注释应该是:
@Before("execution(* com.beans.Student.addCustomer(..))")
public void logBefore(JoinPoint jp) {
System.out.println("logbefore");
System.out.println("method " + jp.getSignature().getName());
}
或者使用XML Bean:
<aop:aspectj-autoproxy />
<bean id="logAspect" class="nch.spring.aop.aspectj.LoggingAspect" />
<aop:config>
<aop:aspect id="aspectLoggging" ref="logAspect">
<aop:pointcut id="pointCutBefore" expression="execution(* com.beans.Student.addCustomer(..)))" />
<aop:before method="logBefore" pointcut-ref="pointCutBefore" />
<aop:aspect/>
<aop:config>
谢谢尼古拉斯,我忘了添加下面的公共类Student{@Pointcut(“execution(*com.beans.Student.addCustomers(..))void addCustomer(){}}谢谢尼古拉斯,我忘了添加下面的公共类Student{@Pointcut(“execution(*com.beans.Student.addCustomers(..)))void addCustomer(){}