Note that there are some explanatory texts on larger screens.

plurals
  1. POOrdering aspects with Spring AOP && MVC
    text
    copied!<p>I am trying to use Spring AOP with Spring MVC Controller. I have 3 aspects, and want the to be in specific order. In order to do this, I use Ordered interface and implement getOrder method:</p> <pre><code>@Aspect @Component public class LoggingAspect implements Ordered{ public int getOrder() { System.out.println("Abra"); return 1; } </code></pre> <p>Adviced class:</p> <pre><code>@Component @Controller public class HomeController { </code></pre> <p>Pointcuts:</p> <pre><code>@Aspect public class SystemArchitecture { @Pointcut("execution (* com.jajah.StorageManager.HomeController.*(..))") public void inHomeController(){} @Pointcut("execution (* com.jajah.StorageManager.HomeController.*(..))") public void loggable(){} @Pointcut("execution (* com.jajah.StorageManager.HomeController.*(..))") public void authenticated(){} } </code></pre> <p>Configuration:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"&gt; &lt;annotation-driven /&gt; &lt;context:annotation-config /&gt; &lt;aop:aspectj-autoproxy proxy-target-class="false"/&gt; &lt;beans:bean id="AuthenticationAspect" class="com.jajah.CommonAspects.SecurityAspects.OAuthAspect"/&gt; &lt;beans:bean id="ErrorHandlingAspect" class="com.jajah.StorageManager.Aspects.ErrorHandlingAspect"/&gt; &lt;!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --&gt; &lt;resources mapping="/resources/**" location="/resources/" /&gt; &lt;!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --&gt; &lt;!-- &lt;beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;beans:property name="prefix" value="/WEB-INF/views/" /&gt; &lt;beans:property name="suffix" value=".jsp" /&gt; &lt;/beans:bean&gt; --&gt; &lt;beans:bean name="homeController" class="com.jajah.StorageManager.HomeController"&gt; &lt;beans:constructor-arg&gt; &lt;beans:ref bean="CloudStorage"/&gt; &lt;/beans:constructor-arg&gt; &lt;beans:constructor-arg&gt; &lt;beans:ref bean="ConfigurationContainer"/&gt; &lt;/beans:constructor-arg&gt; &lt;/beans:bean&gt; &lt;beans:bean id="CloudStorage" name="CloudStorage" class="com.jajah.StorageManager.CloudStorageProxy" scope="singleton"&gt; &lt;beans:constructor-arg&gt; &lt;beans:ref bean="ConfigurationContainer"/&gt; &lt;/beans:constructor-arg&gt; &lt;/beans:bean&gt; &lt;beans:bean id ="ConfigurationContainer" class="com.jajah.StorageManager.ConfigurationContainer" scope="singleton"/&gt; &lt;/beans:beans&gt; </code></pre> <p>The getOrder doesn't do the trick. I will appreciate any practical advice, or if you don't have the exact answer I will appreciate any theoretical knowledge about the Spring Proxy and the weaving mechanism.</p> <p>I will post any Code/Configuration required upon demand. Thanks for reading.</p> <p>Update: 1. I tried @Order(1) with same result. 2. I tried to move aspects to same package, it changed their order, but I still couldn't control it.</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