java - 嵌套异常是 java.lang.IllegalArgumentException: error at::0 找不到引用的切入点

标签 java spring-aop

我是 AOP 新手。读《 Spring 在行动》一书。其中有 AOP 章节和示例。我用 XML 做了它,一切都很好。有一个 Aspects 带注释配置的例子。我按照书上的方法做了一合一,但是不行。请帮忙。

错误:

    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: 
    Error creating bean with name 'guitar' defined in class path resource [springIdolBeansAnnotation.xml]: 
    Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 c
    an't find referenced pointcut performance

包含名为 springIdolBeansAnnotation.xml 的 bean 的文件:

<?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/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

    <bean id="guitar" class="com.springinaction.springidol.Guitar"/>
    <aop:aspectj-autoproxy/>
    <bean id="kenny2" class="com.springinaction.springidol.Instrumentalist">
        <property name="song" value="Jingle B"/>
        <property name="instrument" ref="guitar"/>
    </bean>
    <bean id="audience" class="com.springinaction.springidol.Audience"/>
</beans>

文件吉他:

package com.springinaction.springidol;

public class Guitar implements Instrument {

    @Override
    public void play() {
        System.out.println("Guitar playing");
    }

}

文件乐器演奏家:

package com.springinaction.springidol;

public class Instrumentalist implements Performer {

    private String song;

    private Instrument instrument;

    public Instrumentalist(){}

    @Override
    public void perform() throws Exception {
        System.out.println("Playing "+song + " : ");
        instrument.play();
    }

    public String getSong() {
        return song;
    }

    public void setSong(String song) {
        this.song = song;
    }

    public String screamSong(){
        return song;
    }

    public void setInstrument(Instrument instrument) {
        this.instrument = instrument;
    }

}

文件受众(方面):

package com.springinaction.springidol;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class Audience {
    @Pointcut("execution(* com.springinaction.springidol.Performer.perform(..))")
    public void performance(){}

    @Before("performance()")
    public void takeSeats(){
        System.out.println("The audience is takig their seats");
    }

    @Before("performance()")
    public void turnOffCellPhones(){
        System.out.println("The audience is turning off their cellphones");
    }

    @AfterReturning("performance()")
    public void applaud(){
        System.out.println("CLAP CLAP CLAP CLAP CLAP");
    }

    @AfterThrowing("performance()")
    public void demandRefund(){
        System.out.println("Boo! We want our money back");
    }

    @Around("performance()")
    public void watchPerformance(ProceedingJoinPoint joinpoint){
        try {
            System.out.println("Theaudienceistakingtheirseats.");
            System.out.println("Theaudienceisturningofftheircellphones");
            long start=System.currentTimeMillis();
            joinpoint.proceed();
            long end=System.currentTimeMillis();
            System.out.println("CLAP CLAP CLAP CLAP CLAP");
            System.out.println("Theperformancetook"+(end-start)
            + "milliseconds.");
        } catch(Throwable t){
            System.out.println("Boo!Wewantourmoneyback!");
        }
    }
}

主文件:

package com.springinaction.springidol;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringIdolMain {

    public static void main(String[] args) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("springIdolBeansAnnotation.xml");
        Performer performer = (Performer) ctx.getBean("kenny2");
        try {
            performer.perform();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

最佳答案

是的,这可能是因为旧 jar 。我假设您使用 spring 3.x jars 和 confiduration 。尝试使用最新的 jar

几天前我遇到了类似的问题,org.springframework.beans.factory.BeanCreationException:创建bean时出错

就我而言,这是旧 jar 的问题 My issue

您可以尝试使用最新的 jar 运行您的应用吗:

aopalliance-1.0.jar
asm-3.3.1.jar
aspectj-1.7.1.jar
aspectjrt-1.7.0.jar
aspectjweaver-1.7.0.jar
cglib-2.2.2.jar

关于java - 嵌套异常是 java.lang.IllegalArgumentException: error at::0 找不到引用的切入点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12502498/

相关文章:

java - jboss/wildfly 10 中具有 SLF4J 日志记录的映射诊断上下文 (MDC) 已被清除

java - 列出用户输入

java - 方面永远不会被调用

java - 父抽象类中方法的切入点

Spring AOP 非法参数异常 : Cannot convert value of type [$Proxy12

java - Spring 每个方法都应该使用 AOP 代理 bean 调用

java - 无法将 Spring 方面设置为最低顺序

java - Android R 文件问题和 manifest.xml 问题

java - 覆盖主页按钮的功能

java - 使用 GridBagLayout 修剪 JTable 下面的列空间