Я пытаюсь использовать Spring AOP с Spring MVC Controller. У меня есть 3 аспекта, и я хочу, чтобы они были расположены в определенном порядке. Для этого я использую интерфейс Ordered и реализую метод getOrder:
@Aspect
@Component
public class LoggingAspect implements Ordered{
public int getOrder() {
System.out.println("Abra");
return 1;
}
Советуемый класс:
@Component
@Controller
public class HomeController {
Указатели:
@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(){}
}
Конфигурация:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<annotation-driven />
<context:annotation-config />
<aop:aspectj-autoproxy proxy-target-class="false"/>
<beans:bean id="AuthenticationAspect" class="com.jajah.CommonAspects.SecurityAspects.OAuthAspect"/>
<beans:bean id="ErrorHandlingAspect" class="com.jajah.StorageManager.Aspects.ErrorHandlingAspect"/>
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<!-- <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean> -->
<beans:bean name="homeController" class="com.jajah.StorageManager.HomeController">
<beans:constructor-arg>
<beans:ref bean="CloudStorage"/>
</beans:constructor-arg>
<beans:constructor-arg>
<beans:ref bean="ConfigurationContainer"/>
</beans:constructor-arg>
</beans:bean>
<beans:bean id="CloudStorage" name="CloudStorage" class="com.jajah.StorageManager.CloudStorageProxy" scope="singleton">
<beans:constructor-arg>
<beans:ref bean="ConfigurationContainer"/>
</beans:constructor-arg>
</beans:bean>
<beans:bean id ="ConfigurationContainer" class="com.jajah.StorageManager.ConfigurationContainer" scope="singleton"/>
</beans:beans>
Метод getOrder не помогает. Буду благодарен за любой практический совет, или если у вас нет точного ответа, буду благодарен за любые теоретические знания о Spring Proxy и механизме плетения.
Я выложу любой код/конфигурацию по требованию. Спасибо за прочтение.
Обновление: 1. Я попробовал @Order(1) с тем же результатом. 2. Я попробовал переместить аспекты в тот же пакет, это изменило их порядок, но я все еще не мог управлять этим.