Spring 未找到匹配的工厂方法:工厂方法';aspectOf()和#x27;
我有以下几方面:Spring 未找到匹配的工厂方法:工厂方法';aspectOf()和#x27;,spring,aop,aspectj,spring-roo,Spring,Aop,Aspectj,Spring Roo,我有以下几方面: 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.Ty
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>
我很惊讶,因为我很确定这个配置以前工作得很好。更重要的是,这是一个SpringRoo项目,因此所有aspectJ配置都应该很好
有人可以帮忙吗?这可能是因为您的aspect没有编译,无论出于何种原因,您是否可以尝试向aspectj weaver插件添加更多诊断,并查看控制台上打印的内容,大致如下:
<configuration>
<outxml>true</outxml>
<showWeaveInfo>false</showWeaveInfo>
<Xlint>warning</Xlint>
<verbose>true</verbose>
...
</configuration>
真的
假的
警告
真的
...
另外,由于您使用的是原始aspectj,因此实际上不需要使用用于触发Spring AOP的
。我遇到了相同的错误消息。我在这里看到了罗兹基的答案,解决了这个问题:
为了记录答案,我在这里复制了它:
罗茨基写道:
嗨
我也有同样的问题。我发现,对于aop.xml文件中的方面类,也需要启用编织。在您的情况下,它是(参见突出显示的部分):
希望能有帮助
多亏了你的建议,我才知道为什么这相位没有被编译。非常感谢。@balteo,你能具体说明你的问题的答案是什么吗?我的方面还没有编译。如果没有编译,请尝试上面的配置,您将看到编译错误。感谢您的快速响应。我对这个问题的解决方案是不同的,我把它作为一个单独的答案添加了进去。
<configuration>
<outxml>true</outxml>
<showWeaveInfo>false</showWeaveInfo>
<Xlint>warning</Xlint>
<verbose>true</verbose>
...
</configuration>
<!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>