2012-08-27 15 views
6

मैं निम्नलिखित पहलू है:कोई मिलती-जुलती कारखाने विधि पाया: कारखाने विधि 'aspectof()'

package trc.suivi.aspects; 

import java.util.Date; 

import org.apache.log4j.Logger; 
import org.springframework.beans.factory.annotation.Autowired; 

import trc.suivi.domain.EvenementPli; 
import trc.suivi.domain.Pli; 
import trc.suivi.domain.TypeEvenement; 
import trc.suivi.repository.EvenementPliRepository; 

public aspect PliEventManagerAspect { 

    private static final Logger log = Logger.getLogger(PliEventManagerAspect.class); 

    @Autowired 
    private EvenementPliRepository evenementPliRepository; 

    public PliEventManagerAspect() { 
    } 

    pointcut catchEMPersist(Pli pli) : (execution(* trc.suivi.repository.PliRepository+.save(*)) && args(pli)); 
    pointcut catchEMPersist() : (execution(trc.suivi.domain.Pli.persist())); 

    after(Pli pli) returning: catchEMPersist(pli) { 
     log.debug("catchEMPersist(pli)"); 
     EvenementPli ev = new EvenementPli(); 
     ev.setDateCreation(new Date()); 
     ev.setType(TypeEvenement.creation); 
     ev.setMessage("Création d'un pli"); 
     evenementPliRepository.save(ev);   
    } 

    after() returning: catchEMPersist() { 
     log.debug("catchEMPersist()"); 
     EvenementPli ev = new EvenementPli(); 
     ev.setDateCreation(new Date()); 
     ev.setType(TypeEvenement.creation); 
     ev.setMessage("Création d'un pli"); 
     evenementPliRepository.save(ev);   
    } 

} 

और निम्नलिखित xml config:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"> 
    <aop:aspectj-autoproxy /> 
    <bean class="trc.suivi.aspects.PliEventManagerAspect" factory-method="aspectOf"/> 
</beans> 

मेरे एप्लिकेशन शुरू, मैं यह:

No matching factory method found: factory method 'aspectOf()'. Check that a method with the specified name exists and that it is static. 

मैं काफी डूब गया हूं क्योंकि मुझे पूरा यकीन है कि यह कॉन्फ़िगर पहले ठीक काम करता है। स्प्रिंग रू प्रोजेक्ट यह और अधिक है, इसलिए सभी पहलू जे कॉन्फ़िगरेशन ठीक होना चाहिए।

क्या कोई मदद कर सकता है?

उत्तर

3

यह शायद, क्योंकि आपके पहलू जो भी कारण के लिए संकलित नहीं किया है तुम कोशिश कर सकते है और अपने AspectJ बुनकर प्लगइन के लिए और अधिक नैदानिक ​​जोड़ सकते हैं और देखते हैं कि क्या कंसोल पर मुद्रित किया जा रहा है, इन पंक्तियों के साथ:

<configuration> 
    <outxml>true</outxml> 
    <showWeaveInfo>false</showWeaveInfo> 
    <Xlint>warning</Xlint> 
    <verbose>true</verbose> 
       ... 
</configuration> 

चूंकि आप कच्चे पहलू का उपयोग कर रहे हैं, इसलिए आपको वास्तव में <aop:aspectj-autoproxy/> का उपयोग करने की आवश्यकता नहीं है जिसका उपयोग स्प्रिंग एओपी को ट्रिगर करने के लिए किया जाता है।

+0

मैं यह पता लगाने में सक्षम था कि पहलू को आपके सुझाव के लिए क्यों संकलित नहीं किया गया था। बहुत बहुत धन्यवाद। – balteo

+0

@balteo, क्या आप निर्दिष्ट कर सकते हैं कि आपकी विशेष समस्या का उत्तर क्या था? – alfredaday

+1

मेरा पहलू संकलित नहीं किया गया था। अगर आपका संकलन नहीं करता है, तो उपरोक्त कॉन्फ़िगरेशन आज़माएं, आपको संकलन त्रुटियां दिखाई देगी। – balteo

2

मुझे एक ही त्रुटि संदेश आ रहा था। मैं rozky का जवाब यहाँ पर देख कर इसे हल: http://forum.springsource.org/showthread.php?79928-NoSuchMethodError-Aspect-aspectOf%28%29

जवाब रिकॉर्डिंग के लिए, मैं इसे यहाँ कॉपी किया है:

rozky लिखा है:

हाय,

मैं एक ही समस्या थी। मुझे पता चला कि बुनाई को aop.xml फ़ाइल में पहलू वर्गों के लिए भी सक्षम करने की आवश्यकता है। आपके मामले में यह है (हाइलाइट किया गया हिस्सा देखें):

<!DOCTYPE aspectj PUBLIC 
     "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd"> 
<aspectj> 
    <weaver options="-verbose -showWeaveInfo -debug"> 
     <!-- only weave classes in our application-specific packages --> 
     <include within="com.mypackage.*"/> 
     <include within="foo.*"/> <!-- this is the highlighted line --> 
    </weaver> 
    <aspects> 
     <!-- weave in just this aspect --> 
     <aspect name="foo.ProfilingAspect"/> 
    </aspects> 
</aspectj> 

आशा है कि इससे मदद मिलती है।

संबंधित मुद्दे