No matching factory method found: factory method 'aspectOf()'

不羁岁月 提交于 2019-12-01 16:54:14

问题


I have the following aspect:

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);        
    }

}

And the following 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>

When I start my app, I get this:

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

I am quite dumbfounded as I am pretty sure this config worked fine before. What is more this is a Spring Roo project so all the aspectJ config should be fine.

Can anyone please help?


回答1:


This is probably because your aspect has not compiled for whatever reason, can you try and add more diagnostic to your aspectj weaver plugin and see what is being printed on the console, along these lines:

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

Also since you are using raw aspectj you don't really need to use <aop:aspectj-autoproxy/> which is used to trigger Spring AOP.




回答2:


I was having the same error message come up. I solved it by looking at rozky's answer here: http://forum.springsource.org/showthread.php?79928-NoSuchMethodError-Aspect-aspectOf%28%29

For the sake of recording the answer, I've copied it here:

rozky wrote:

Hi,

I had a same problem. I found out that the weaving need to be enabled also for aspect classes in aop.xml file. In your case it is (see highlighted part):

<!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>

Hope it helps.



来源:https://stackoverflow.com/questions/12144606/no-matching-factory-method-found-factory-method-aspectof

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!