我试图让我的第一个基于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。 –