[英]Curious Spring AOP Exception
我試圖使我的第一個基於Spring AOP的MethodInterceptors正常工作,並且我的超簡單 XML配置遇到了一些奇怪的異常。
我有一個類名為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]
我唯一的猜測是,在pointcut屬性中指定的模式某種程度上是錯誤的(也許我需要以某種方式將ConsumptionRate
包含在其中)。 但是幾乎找不到該XML Schema的文檔,我在這里陷入了困境。
有人有任何建議或發現有什么建議嗎? 提前致謝!
順便說一句,如果有人知道某個站點或記錄所有這些<aop>
標簽及其屬性的任何文獻,請告訴我。 已經向我推薦了Spring AOP參考的第6章,盡管這是一個非常全面的教程,但它僅包含示例,並且沒有記錄整個xml模式。
確保您使用的是完全合格的類名(或也匹配的通配符版本),否則類掃描器將找不到它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.