Spring AOP(方面)未执行

我正在使用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 hasonSubmit()method, which get called from web page. I have

separateapplicationContext.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从未被调用。我不确定丢失了什么,或者我做错了。请帮我..

谢谢

回答:

终于解决了。

我想我缺少了AspectJ-Maven-Plug。从spring到编织各方面都需要。虽然没有教程提供此信息。在我的pom.xml中添加了以下内容。

<plugin>

<groupId>org.codehaus.mojo</groupId>

<artifactId>aspectj-maven-plugin</artifactId>

<version>1.0</version>

<dependencies>

<dependency>

<groupId>org.aspectj</groupId>

<artifactId>aspectjrt</artifactId>

<version>1.6.1</version>

</dependency>

<dependency>

<groupId>org.aspectj</groupId>

<artifactId>aspectjtools</artifactId>

<version>1.6.1</version>

</dependency>

</dependencies>

<executions>

<execution>

<goals>

<goal>compile</goal>

<goal>test-compile</goal>

</goals>

</execution>

</executions>

<configuration>

<outxml>true</outxml>

<verbose>true</verbose>

<showWeaveInfo>true</showWeaveInfo>

<aspectLibraries>

<aspectLibrary>

<groupId>org.springframework</groupId>

<artifactId>spring-aspects</artifactId>

</aspectLibrary>

</aspectLibraries>

<source>1.6</source>

<target>1.6</target>

</configuration>

</plugin>

谢谢你们

以上是 Spring AOP(方面)未执行 的全部内容, 来源链接: utcz.com/qa/398616.html

回到顶部