AOP: java.lang.IllegalArgumentException: error in :: 0 cannot find pointcut link

I am new to AOP. I had such a problem.

package org.suman.Aspect; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; @Aspect public class LoginAspect { //@Before("execution(public String getName())") //@Before("execution(public String org.suman.Model.Triangle.getName())") //@Before("execution(* get*())") //@Before("execution(* get*(..))") //@Before("execution(* org.suman.Model.*.get*())") //@Before("execution(* get*())&& within(org.suman.Model.Circle)") @Before("execution(* get*())&& allCircle()") //@Before("allGetters() && allCircle()") public void LoginAdvice() { System.out.println("Advice run.. getMethod is called"); } @Before("execution(* get*())") //@Before("allGetters()") public void SecondAdvice() { System.out.println("this is a second Advice"); } @Pointcut("execution(* get*())") public void allGetters(){} //@Pointcut("execution (* * org.suman.Model.Circle.*(..))") @Pointcut("within(org.suman.Model.Circle)") public void allCircle(){} } 

when using the pointcut method from allGetters() to LoginAdvice , if I use @Before("execution(* get*())") , then there is no error, but if I use @Before("allGetters()") , it gives an error

java.lang.IllegalArgumentException: error in :: 0 cannot find reference pointcut allGetters

if I use @Before("execution(* get*())&& within(org.suman.Model.Circle)") instead of the method name, it works.

My XML is like this:

 <?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" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <!-- <context:annotation-config /> --> <aop:aspectj-autoproxy /> <bean name="triangle" class="org.suman.Model.Triangle"> <property name="name" value="Triangle Name"></property> </bean> <bean name="circle" class="org.suman.Model.Circle"> <property name="name" value="Circle name"></property> </bean> <bean name="shapeService" class="org.suman.Services.ShapeService" autowire="byName"></bean> <bean name="loginAspect" class="org.suman.Aspect.LoginAspect"></bean> </beans> 

Please solve the problem with pointcut with which it accepts a method

+11
source share
11 answers

I had this problem - using the @Pointcut method in the "placeholder" method gave me the error "cannot find a link to pointcut".

It was decided to simply update the AspectJ libraries with the maven dependencies on this:

  <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.5.4</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.5.4</version> </dependency> 

to that

  <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.7.0</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.7.0</version> </dependency> 
+25
source

I ran into the same problem. Once I replaced aspectjweaver with aspectjweaver-1.6.11.M2.jar version. It all started smoothly.

+3
source

The issue could also be caused by starting an earlier version of JDK9 access.

Maven may prefer a newer version of Java over the JVM in PATH .

In my case, I run Spring with Swagger2 through Maven on Ubuntu 15.04, and I installed java-8-oracle and java-9-oracle (and a few more versions). My java -version derived from PATH says 1.8.0_72 , but when I run Maven and change /usr/bin/mvn to echo JAVA_HOME , it shows that I chose /usr/lib/jvm/java-9-oracle .

Exporting JAVA_HOME to /usr/lib/jvm/java-8-oracle forced Maven to use the correct version of Java, and this led to problems with the AOP weaving of point references for posting Spring injections.

+2
source

Use aspectjweaver and aspectjrt version 1.8.10

+1
source

I believe you need to add another template:

 @Pointcut("execution(* get*())") 

change it to:

 @Pointcut("execution(* *get*())") 
0
source

You should change aspectJWeaver version as 1.6.x

0
source

I had this problem because the project was compiled in Java 1.6, but the tomcat server is running on Java 8.

0
source

I also had a similar problem with @Before advice not accepting the @Pointcut method name as an argument. I got this fix by changing the dependency version to:

 <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.6.11</version> </dependency> <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.6.11</version> </dependency> 

Now it works fine.

0
source

This is a dependency problem. The following jar files or dependencies of the same version should be used to avoid such problems:

 <dependency> <groupId>aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.5.2</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.8.10</version> </dependency> <dependency> <groupId>asm</groupId> <artifactId>asm</artifactId> <version>3.3.1</version> </dependency> <dependency> <groupId>aopalliance</groupId> <artifactId>aopalliance</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>2.2.2</version> </dependency> 
0
source

Add this maven dependencies. This will solve your problem.

Change version to 1.6.12

0
source

Change the aspectjeaver version to the latest version and expand it ...

-one
source

All Articles