2012-02-25 136 views
0

我得到这个错误的Web应用程序启动Spring AOP的表达

产生的原因:org.springframework.beans.factory.BeanCreationException:错误创建名称为豆“org.springframework.aop.aspectj.AspectJPointcutAdvisor#0 ':bean的实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化bean类[org.springframework.aop.aspectj.AspectJPointcutAdvisor]:构造函数抛出异常;嵌套的例外是java.lang.IllegalArgumentException异常:错误的:: 0切入点

这里的显示在底部

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

我的切入点的XML的一部分.....事情省略

正式绑定
<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() "); 
    } 

的expressi对我来说似乎没有问题。任何指针?我们使用的是aspectj 1.6.2。谢谢。

回答

0

我可以确认您的AspectJ表达式是否正常。我做了一个测试版本,使用你给我们的上面的东西,它的工作。

我没有在Web容器中做过 - 我在Eclipse中做了一个独立的Spring应用程序,使用AspectJ工具1.6.6和AspectJ weaver 1.6.8和Spring 3.1库,所以稍微超过了你的设置的版本。

这里是我有工作:在我的类路径

的方面相关的jar文件:

  • org.springframework.aop-3.1.0
  • org.springframework.aspects-3.1 0.0
  • com.springsource.org.aspectj.tools-1.6.6
  • com.springsource.org.aspectj.weaver-1.6.8
  • 融为一体。 springsource.org.aopalliance-1.0.0

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

添加以下bean定义为相同的Spring XML配置文件:

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

目标类有你testBAM()方法。

的BamAspectAround的代码如下所示:

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

主要方法有这样的:

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

而且它打印出局我所料:

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

:我也下载了AspectJ 1.6.2,并把它的编织器罐子d将它的工具jar放到我的classpath中(删除1.6.8),上面的工作也可以运行,所以也许可以在你的设置中尝试一下这个简单的例子,看看你的web部署版本中缺少了什么。