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

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 launch my application, I get the following:

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

I am very stunned, as I am sure that this configuration worked fine. Moreover, this is a Spring Roo project, so the whole aspectJ configuration should be fine.

Can anybody help?

+6
source share
2 answers

This is probably due to the fact that your aspect is not compiled for any reason, can you try adding additional diagnostics to your aspectj plugin and see what is printed on the console, according to these lines:

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

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

+4
source

I got the same error message. I solved this by looking at the rozky answer here: http://forum.springsource.org/showthread.php?79928-NoSuchMethodError-Aspect-aspectOf%28%29

To record the answer, I copied it here:

rozky wrote:

Hi,

I had the same problem. I found out that we need to use weaving for aspect classes in the aop.xml file. In your case, this (see Selected 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 this helps.

+2
source

Source: https://habr.com/ru/post/923875/


All Articles