AOP/Aspect-J Overview and Config

aop-image-1
(1) Overview

AOP (Aspect Oriented Programming) is one of key features in Spring framework beside (DI).
In AspectJ, which is more flexible and powerful compared to Spring AOP, There are following advices are available: (Source Code)


(2) Configure

<annotation-driven />
<context:component-scan base-package="com.ns.spring" />

<!-- AOP -->
<aop:aspectj-autoproxy>
    <aop:include name="aopBefore" />
    <aop:include name="aopAfter" />
    <aop:include name="aopAround" />
</aop:aspectj-autoproxy>

<!-- "id": Unique ID used by programs to identify the class. Unlike "name"  -->
<!--       it cannot be more than one reference from the same Java object   -->
<!-- "prototype": New instance each time when called                        -->
<!-- "singleton": Single instance per Spring IoC container                  -->
<beans:bean id="aopBefore"  class="com.ns.spring.aop.advise.AspectBefore" scope="prototype"/>
<beans:bean id="aopAfter"   class="com.ns.spring.aop.advise.AspectAfter"  scope="prototype"/>
<beans:bean id="aopAround"  class="com.ns.spring.aop.advise.AspectAround" scope="prototype"/>

   <properties>
.
      <org.aspectj-version>1.7.4</org.aspectj-version>
   </properties>
   <dependencies>
.
.
.
      <!-- AspectJ -->
      <dependency>
         <groupId>org.aspectj</groupId>
         <artifactId>aspectjrt</artifactId>
         <version>${org.aspectj-version}</version>
         <scope>runtime</scope>
      </dependency>
      <dependency>
         <groupId>org.aspectj</groupId>
         <artifactId>aspectjtools</artifactId>
         <version>${aspectj.version}</version>
      </dependency>
      <dependency>
         <groupId>org.aspectj</groupId>
         <artifactId>aspectjweaver</artifactId>
         <version>1.8.5</version>
      </dependency>
      <dependency>
         <groupId>cglib</groupId>
         <artifactId>cglib</artifactId>
         <version>2.2.2</version>
      </dependency>
   </dependencies>
</project>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.