【问题标题】:Spring AOP expressionSpring AOP 表达式
【发布时间】:2012-02-26 02:09:19
【问题描述】:

我在 webapp 启动时收到此错误

原因:org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.aop.aspectj.AspectJPointcutAdvisor#0”的bean时出错:bean实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 bean 类 [org.springframework.aop.aspectj.AspectJPointcutAdvisor]:构造函数抛出异常;嵌套异常是 java.lang.IllegalArgumentException: error at ::0 切入点中的正式未绑定

这是 xml 的一部分,在底部显示了我的切入点

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

.....省略的东西

  <aop:config>
    <aop:aspect id="bamAspectAroundID" ref="bamAspectAround">
        <aop:pointcut id="bamAroundMethodPointcut" expression="execution(* testBA*(..))" />
        <aop:around method="aspectAroundMethod" pointcut-ref="bamAroundMethodPointcut"/>
    </aop:aspect>
  </aop:config>

在我的一个课程中,我有一个虚拟方法

    public void testBAM() {
       System.out.println("in testBAM() ");
    }

我觉得这个表达还可以。任何指针?我们正在使用aspectj 1.6.2。谢谢。

【问题讨论】:

    标签: spring aop


    【解决方案1】:

    我可以确认您的 AspectJ 表达式没有问题。我使用您在上面给我们的内容做了一个测试版本,它有效。

    我没有在 Web 容器中执行此操作 - 我在 Eclipse 中使用 AspectJ 工具 1.6.6 和 AspectJ weaver 1.6.8 和 Spring 3.1 库作为独立 Spring 应用程序执行此操作,因此在设置方面略领先于您的设置版本。

    这是我所做的工作:

    我的类路径中与方面相关的 jar 文件是:

    • org.springframework.aop-3.1.0
    • org.springframework.aspects-3.1.0
    • com.springsource.org.aspectj.tools-1.6.6
    • com.springsource.org.aspectj.weaver-1.6.8
    • com.springsource.org.aopalliance-1.0.0

    我的 xml 配置的 AOP 部分看起来和你的完全一样 - 没有变化。

    我在同一个 spring xml 配置文件中添加了以下 bean 定义:

    <bean id="aspectTarget"    class="foo.bam.Target" />
    <bean id="bamAspectAround" class="foo.bam.BamAspectAround" />
    

    Target 类有你的testBAM() 方法。

    BamAspectAround 的代码如下所示:

    public class BamAspectAround {
      public void aspectAroundMethod(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println(">>> BamAspectAround Before");
        joinPoint.proceed();
        System.out.println("<<< BamAspectAround After");
      }
    }
    

    main方法有这个:

    Target t = (Target)ctx.getBean("aspectTarget");
    t.testBAM();
    

    它会打印出我所期望的:

    >>> BamAspectAround Before
    in testBAM() 
    <<< BamAspectAround After
    

    注意:我还下载了 AspectJ 1.6.2 并将它的 weaver jar 和它的工具 jar 放入我的类路径(删除 1.6.8 的),上面也可以,所以也许试试这个简单的以您的设置为例,看看您的网络部署版本中缺少什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-03
      • 1970-01-01
      相关资源
      最近更新 更多