Results 1 to 4 of 4

Thread: Ordering aspects & interceptors

  1. #1
    Join Date
    Nov 2006
    Posts
    5

    Default 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 at 08:45 PM.

  2. #2
    Join Date
    Aug 2006
    Posts
    236

    Default

    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 at 02:52 AM.

  3. #3
    Join Date
    Nov 2006
    Posts
    5

    Default

    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 ?

  4. #4
    Join Date
    Aug 2006
    Posts
    236

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •