2016-08-21 5 views
0

Я использую java 8, весна 4.3 и apsectj 1.8.9. Почему я получаю нижеприведенную ошибку для приведенного ниже кода. Если я использую @Before ("com. beans.Student.addCustomer() ") без pointcut Я получаю эту ошибку ошибки в 0, не могу найти ссылку pointcut. При использовании @Before с poincut я не получаю ошибку.Ошибка пружины AOP при 0 не может найти ссылку 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()); 
    } 
} 

Student:

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> 
+0

спасибо Nikolas, я забыл добавить belowpublic класс Student { \t @Pointcut ("исполнения (* com.beans. Student.addCustomers (..)) ") \t недействительными addCustomer() { \t \t \t }} –