2012-02-25 100 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部署版本中缺少了什麼。