我正在使用 Spring 2.5.6、asm 1.5.3、aspectjrt/aspectjweaver 1.6.1、cglib 2.1_3 在我的基于 Web 的 Spring 应用程序中,我有以下类:
package uk.co.txttools.aspects;
@Aspect
public class LoggingAspect {
@Before("execution(* uk.co.txttools.web.controller.compose.PreviewMessageController.set*(..))")
public void setLoggingAdvice(){
System.out.println("********************************* Advice run..... set mothod called....");
}
@AfterThrowing("execution(* uk.co.txttools.web.controller.compose.PreviewMessageController.onSubmit(..) throws java.lang.Exception)")
public void hadleException(){
System.out.println("================= PreviewMessageController =========== ON SUBMIT Exception Throwen ==================");
}
@Before("execution(* uk.co.txttools.web.controller.compose.PreviewMessageController.onSubmit(..) throws java.lang.Exception)")
public void OnSubmitAspect(){
System.out.println("================= PreviewMessageController =========== ON SUBMIT CALLED ==================");
}
}
我有一个Controller:uk.co.txttools.web.controller.compose.PreviewMessageController
which has
onSubmit() method, which get called from web page.
I have separate
applicationContext.xml` 文件。
我的springapp-servlet.xml
(在带有 org.springframework.web.servlet.DispatcherServlet 的 web.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"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
<aop:aspectj-autoproxy proxy-target-class="true" />
<bean id="loggingAspect" class="uk.co.txttools.aspects.LoggingAspect" />
.
.
下面在同一个 xml 文件中PreviewMessageController
进行初始化,这意味着我的 Controller 和 Aspect live 是同一个容器。
运行应用程序时我没有遇到任何异常,但我的方面类LoggingAspect
从未被调用。我不确定缺少什么或我做错了。请帮我..
谢谢