我試圖讓我的第一個基於Spring AOP的MethodInterceptors正在工作,並且我正在用我的超簡單 XML配置獲得一些奇怪的例外。好奇的春天AOP異常
我有一個名爲Food
的類,它有一個名爲eat(ConsumptionRate rate)
的方法,它將ConsumptionRate
類型的對象作爲其唯一參數;每一個具體方法(Food::eat(ConsumptionRate)
)被調用的時候,我想MethodInterceptor
執行 「周圍」:
public class FoodInterceptor implements MethodInterceptor
{
public Object invoke(MethodInvocation method)
{
try
{
// Do some stuff before target method executes
Object result = method.proceed();
return result;
}
finally
{
// Do some stuff after target method executes.
}
}
}
這裏是全部我的xml配置(aop-config.xml
):
<?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 name="foodInterceptor" class="com.me.foodproject.core.FoodInterceptor"/>
<aop:config>
<aop:advisor advice-ref="foodInterceptor"
pointcut="execution(public * Food.eat(..))"/>
</aop:config>
項目建好(編譯等),但是當我運行它時,我得到以下錯誤:
java.lang.IllegalArgumentException: warning no match for this type name: Food [Xlint:invalidAbsoluteTypeName]
只有我的猜測是,在切入點屬性指定的模式是某種錯誤的(也許我需要在它ConsumptionRate
不知)。但是這個XML Schema的文檔幾乎不可能找到,而我在這裏黑暗中徘徊。
任何人有任何建議或看到的東西,他們跳了出來?提前致謝!
作爲旁邊,如果有人知道一個網站或任何文件,所有這些文件<aop>
標籤及其屬性,請讓我知道。 Spring AOP的參考的第6章已經推薦給我的,雖然這是一個非常全面的教程,它只是充滿了例子,並沒有記錄下整個XML架構。
你不是在尋找模式的信息,你正在尋找切入點語法,這是覆蓋在Spring AOP的文檔。有沒有包裝的「Food」類? (嗯,這個* *問題,你需要的切入點語法:) –
@戴夫嗨 - 感謝您的答覆。當你問「有沒有包裝的食物時,我可以問你的意思嗎?」所有東西都編譯得很好,它只是在運行時出現故障時。 – IAmYourFaja
我的意思是「沒有包裝,是否有食品類?」因爲這就是你定義切入點的方式。配置文件不會在乎它編譯是否正常 - Spring AOP發生在執行時,而不是編譯,不像AspectJ。 –