I'm trying to get my first-ever Spring AOP-based MethodInterceptors working, and am getting some bizarre exceptions with my ultra-simple XML configuration.
I have a class named Food
which has a method called eat(ConsumptionRate rate)
that takes an object of type ConsumptionRate
as its sole parameter; every time that specific method (Food::eat(ConsumptionRate)
) gets invoked, I want a MethodInterceptor
to execute "around it":
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.
}
}
}
Here is my xml config (aop-config.xml
) in its entirety:
<?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>
Project builds fine (compiles, etc.), but when I run it I get the following error:
java.lang.IllegalArgumentException: warning no match for this type name: Food [Xlint:invalidAbsoluteTypeName]
My only guess is that the pattern specified in the pointcut attribute is somehow wrong (maybe I need to include ConsumptionRate
in it somehow). But the documentation for this XML Schema has been nearly impossible to find, and I'm stumbling around in the dark here.
Anybody have any suggestions or see something that jumps out at them? Thanks in advance!
As an aside, if someone knows of a site or any literature that documents all of these <aop>
tags and their attributes, please let me know. Chapter 6 of the Spring AOP reference has been recommended to me, and although that is a very comprehensive tutorial, it is just full of examples, and does not document the entire xml schema.