Note that there are some explanatory texts on larger screens.

plurals
  1. POimplement AOP for Controllers in Spring 3
    primarykey
    data
    text
    <p>How do I implement AOP with an annotated Controller?</p> <p>I've search and found two previous posts regarding the problem, but can't seem to get the solutions to work.</p> <p><a href="https://stackoverflow.com/questions/3991249/how-can-i-combine-aspect-with-controller-in-spring-3">posted solution 1</a></p> <p><a href="https://stackoverflow.com/questions/3310115/spring-aop-advice-on-annotated-controllers">posted solution 2</a></p> <p>Here's what I have:</p> <p>Dispatch Servlet:</p> <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" 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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"&gt; &lt;context:annotation-config/&gt; &lt;context:component-scan base-package="com.foo.controller"/&gt; &lt;bean id="fooAspect" class="com.foo.aop.FooAspect" /&gt; &lt;aop:aspectj-autoproxy&gt; &lt;aop:include name="fooAspect" /&gt; &lt;/aop:aspectj-autoproxy&gt; &lt;/beans&gt; </code></pre> <p>Controller:</p> <pre><code>@Controller public class FooController { @RequestMapping(value="/index.htm", method=RequestMethod.GET) public String showIndex(Model model){ return "index"; } } </code></pre> <p>Aspect:</p> <pre><code>@Aspect public class FooAspect { @Pointcut("@target(org.springframework.stereotype.Controller)") public void controllerPointcutter() {} @Pointcut("execution(* *(..))") public void methodPointcutter() {} @Before("controllerPointcutter()") public void beforeMethodInController(JoinPoint jp){ System.out.println("### before controller call..."); } @AfterReturning("controllerPointcutter() &amp;&amp; methodPointcutter() ") public void afterMethodInController(JoinPoin jp) { System.out.println("### after returning..."); } @Before("methodPointcutter()") public void beforeAnyMethod(JoinPoint jp){ System.out.println("### before any call..."); } } </code></pre> <p>The beforeAnyMethod() works for methods NOT in a controller; I cannot get anything to execute on calls to controllers. Am I missing something?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload