7

私は次の側面を持っています:

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 構成:

<?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.

この設定が以前はうまく機能していたと確信しているので、私はかなり唖然としています。さらに、これは Spring Roo プロジェクトなので、aspectJ の構成はすべて問題ないはずです。

誰でも助けてもらえますか?

4

2 に答える 2

6

これはおそらく、なんらかの理由でアスペクトがコンパイルされていないためです。また、aspectj ウィーバー プラグインにさらに診断を追加して、次の行に沿ってコンソールに表示される内容を確認できますか。

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

<aop:aspectj-autoproxy/>また、生のaspectjを使用しているため、Spring AOPをトリガーするために使用されるものを実際に使用する必要はありません。

于 2012-08-27T19:07:17.223 に答える
3

同じエラーメッセージが表示されていました。ここで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>

それが役に立てば幸い。

于 2012-10-24T17:31:29.657 に答える