Весенняя ошибка AOP в 0 не может найти указанный pointcut
Я использую Java 8, весна 4.3 и AspectJ 1.8.9. Почему я получаю ошибку ниже для кода ниже. Если я использую @Before("com.beans.Student.addCustomer()") без pointcut, я получаю эту ошибку в 0, не могу найти ссылку на pointcut. При использовании @Before с pointcut я не получаю сообщение об ошибке.
Фасоль:
@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>
1 ответ
Решение
У вас неверный синтаксис, используемый для выполнения метода. Ваша аннотация должна быть:
@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>