1

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.

IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
  • You're not looking for schema info, you're looking for pointcut syntax, which is covered in the Spring AOP docs. Is there a class `Food` without a package? (Well, for *this* problem, you need the pointcut syntax :) – Dave Newton Sep 28 '11 at 16:03
  • Hi @Dave - thanks for the response. Can I ask what you mean when you ask "Is there a class Food without a package?" Everything compiles perfectly fine, its just at runtime when things go haywire. – IAmYourFaja Sep 28 '11 at 16:10
  • I mean "Is there a `Food` class, without a package?" because that's how you've defined the pointcut. The config file won't care if it compiles fine--Spring AOP happens at execution, not compilation, unlike AspectJ. – Dave Newton Sep 28 '11 at 16:12
  • Ahhh, I wasn't using the fully-qualified package name. Thanks @Dave, if you make your response an answer I'll check it for you. – IAmYourFaja Sep 28 '11 at 16:21

1 Answers1

3

Make sure you're using the fully-qualified class name (or a wildcard version that also matches), otherwise the class scanner won't find it.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302