【问题标题】:No matching factory method found: factory method 'aspectOf()'找不到匹配的工厂方法:工厂方法“aspectOf()”
【发布时间】:2012-08-27 15:05:01
【问题描述】:

我有以下几个方面:

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 配置都应该没问题。

有人可以帮忙吗?

【问题讨论】:

    标签: spring aop aspectj spring-roo


    【解决方案1】:

    这可能是因为您的方面由于某种原因没有编译,您可以尝试向您的 aspectj weaver 插件添加更多诊断信息,并查看控制台上打印的内容,如下所示:

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

    此外,由于您使用的是原始 aspectj,因此您实际上不需要使用用于触发 Spring AOP 的&lt;aop:aspectj-autoproxy/&gt;

    【讨论】:

    • 感谢您的建议,我能够找出为什么方面没有编译。非常感谢。
    • @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>
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-05
      • 1970-01-01
      • 2014-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多