Announcement Announcement Module
Collapse
No announcement yet.
Ordering aspects & interceptors Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ordering aspects & interceptors

    Hi

    I am using the following on the service layer:
    • annotation driven transactions
      Code:
      <tx:annotation-driven transaction-manager="transactionManager" order="100"/>
    • spring modules caching using Cacheable annotation

      Code:
      <bean id="autoproxy" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" />
      <bean id="cachingAttributeSourceAdvisor" class="org.springmodules.cache.interceptor.caching.CachingAttributeSourceAdvisor">
      	<constructor-arg ref="cachingInterceptor" />
      </bean>
    • acegi security using Secured annotation
      Code:
      <bean id="serviceSecurity" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
      
      <bean id="myService" class="org.springframework.aop.framework.ProxyFactoryBean">
      	<property name="interceptorNames">
      		<list>
      			<idref bean="serviceSecurity"/>
      		</list>
      	</property>
      	<property name="target">
      		<bean class="x.y.MyServiceImpl" parent="baseService">
    • Profiling Aspect as per Spring documentation with order set to 1
      Code:
          <bean id="profiler" class="x.y.common.performance.Profiler">
              <property name="order" value="1"/>
          </bean>
          <aop:config>
              <aop:pointcut id="serviceMethod" expression="execution(* x.y.service.impl.*ServiceImpl.*(..))"/>
              <aop:aspect id="profilingAspect" ref="profiler">
                  <aop:around method="profile" pointcut-ref="serviceMethod"/>
              </aop:aspect>
          </aop:config>

    The problem is that these gets applied in somewhat random order. The transaction aspect gets applied last on the way in (good) but the caching interceptor gets applied before the security and profiling aspects (most of the time).

    How do I specify an order to the interceptor(s) passed to the ProxyFactoryBeans and to the autoproxied aspects? I want the following order on the way in:

    1. Profiler
    2. Acegi MethodSecurityInterceptor
    3. MetadataCachingInterceptor
    4. TranscationInterceptor

    Thanks
    Peter
    Last edited by nefilim; Nov 18th, 2007, 08:45 PM.

  • #2
    I believe in Spring 2.x there is something that you can do to order the execution of aspects. I think you need to implement ordered interface (read this in Building Spring Enterprise Application book). In relation to aspectJ you can use DeclarePrecedence annotation and specify the ordering of aspects.
    Last edited by amin; Nov 19th, 2007, 02:52 AM.

    Comment


    • #3
      Thanks, that is indeed what is done with Transaction aspect and the Profiler aspect. There's not much I can do with the Acegi and Spring Modules Caching aspects/interceptors though ?

      Comment


      • #4
        Hmmm...from the top of my head the only thing i can suggest (not sure if this is the only approach) use the decorator pattern. Extend the acegi and caching interceptors and then implement the Ordered interface and then use that class in the configuration file.

        Comment

        Working...
        X