Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
968 views
in Technique[技术] by (71.8m points)

spring aop - AOP : java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut

I am new to AOP. I got some problem like this.

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 pointcut, the method allGetters() to LoginAdvice method, if I use @Before("execution(* get*())") then no error but if I use @Before("allGetters()") then gives error

java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut allGetters

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

My xml 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 by which it takes method

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had this problem - using @Pointcut on a 'placeholder' method was giving me the "can't find referenced pointcut" error.

Solved simply by updating the AspectJ libraries with the maven dependencies from 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 this

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...