Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I combine @Aspect with @Controller in Spring 3?
    text
    copied!<p>I'm trying to setup a Spring 3 Web MVC project, using the @Controller, annotation-based approach.</p> <pre><code>package my.package @Controller @RequestMapping("/admin/*") public class AdminMultiActionController { @RequestMapping(value = "admin.htm", method = RequestMethod.GET) public String showAdminSection() { return "admin"; } </code></pre> <p>My dispatcher-servlet has the following Controller handlers:</p> <pre><code>&lt;context:component-scan base-package="my.package" /&gt; &lt;bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /&gt; &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /&gt; </code></pre> <p>The webapp is running good with the supplied maven artifacts:</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt; &lt;version&gt;3.0.2.RELEASE&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>Now I wanted to add @AspectJ AOP. I got the libs:</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;org.aspectj&lt;/groupId&gt; &lt;artifactId&gt;aspectjweaver&lt;/artifactId&gt; &lt;version&gt;1.6.9&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.aspectj&lt;/groupId&gt; &lt;artifactId&gt;aspectjrt&lt;/artifactId&gt; &lt;version&gt;1.6.9&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>added to my applicationContext.xml:</p> <pre><code>&lt;aop:aspectj-autoproxy/&gt; </code></pre> <p>Made sure to create the relevant bean in the applicationContext.xml as well:</p> <pre><code>&lt;bean id="securityInterceptor" class="my.package.service.SecurityInterceptor"/&gt; </code></pre> <p>And started fleshing out the @Aspect:</p> <pre><code>package my.package.service @Aspect public class SecurityInterceptor { @Pointcut("execution(* showAdminSection(..))")// the pointcut expression private void foo() { System.out.println("fooo"); }// the pointcut signature </code></pre> <p>Now this is where it stopped working. "fooo" is never printed.</p> <p>Could it be, because the pointcutted (spelling?) objects must be spring-managed beans and my @Controller in combination with the DefaultAnnotationHandlerMapping is not perceived as such?</p> <p>Any help would be appreciated. If I forgot to include any information, please ask. Hope someone can help me out here.</p> <p>Thanks a lot!</p>
 

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