AOP on Spring DM


This is a quick introduction how to use Aspect Oriented Programming feature in Spring.


You need the following bundles to use AspectJ style AOP on Spring DM:


Also, do not forget dependency for Spring AOP feature:


BND setting

AOP features call some of the classes implicitly. Even if you include the dependency above in your pom.xml, BND tool cannot create correct Import-Package section for your manifest file. You need to write the AOP dependency explicitly like the following:

Import-Package: *
DynamicImport-Package: org.aspectj.*, org.springframework.aop.*, net.sf.cglib.*, org.aopalliance.*

Now you are ready to use AOP on Spring DM.


First, write a very simple aspect:

   1 package;
   3 import org.aspectj.lang.JoinPoint;
   4 import org.aspectj.lang.annotation.After;
   5 import org.aspectj.lang.annotation.Aspect;
   6 import org.aspectj.lang.annotation.Before;
   8 @Aspect
   9 public class SimpleAspect {
  11         long start;
  13         @Before("execution(* read*(..))")
  14         public void testAspect(JoinPoint joinPoint) {
  15                 System.out.println("=========== Performance test for "
  16                                 + joinPoint.getSignature().toLongString() + " ==============");
  17                 start = System.currentTimeMillis();
  18         }
  20         @After("execution(* read*(..))")
  21         public void testAspect2(JoinPoint joinPoint) {
  22                 long time = System.currentTimeMillis() - start;
  23                 System.out.println("=========== Loading time = " + time
  24                                 + " msec. ==============");
  25         }
  26 }

This aspect means the two methods in the class will be called every time method begin with "read" are executed.

In the bean definition file, you need to define this aspect as a bean. Name for the aspect bean is optional.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
        xmlns:xsi="" xmlns:aop=""
        xmlns:lang="" xmlns:osgi=""

        <aop:aspectj-autoproxy />
        <bean class="" />




(not finished yet)

Outdated_Cytoscape_3.0/Developer/AOP (last edited 2011-02-24 16:16:34 by PietMolenaar)

Funding for Cytoscape is provided by a federal grant from the U.S. National Institute of General Medical Sciences (NIGMS) of the Na tional Institutes of Health (NIH) under award number GM070743-01. Corporate funding is provided through a contract from Unilever PLC.

MoinMoin Appliance - Powered by TurnKey Linux