How to Implement Cross Cutting Concern using AOP in Scala

Cross Cutting Concern using AOP in Scala


In this blog, I have explained that how easily we can implement Cross Cutting Concern such as logging using Aspect Oriented Programming in Scala. These concerns have nothing to do with core business logic. Aspect Oriented Programming is used for encapsulating cross-cutting concerns into re-usable modules. Here we used AspectJ weaver to weave precompiled aspects into project output

First we defined an annotation style aspect scala code:-

This aspect will print Method, its input and result detail, when a method is entered annotated with the @Loggable annotation and finished execution.

Let’s define the @Loggable annotation Java code

Finally define a Sum class to see usage of Aspect

We also need to add META-INF/aop.xml to configure aspect weaver.


        <!-- declare existing aspects to the weaver -->
        <aspect name="com.knoldus.aspect.AnnotationBasedAspect"/>


    <weaver options="-verbose">
        <dump within="com.knoldus.*"/>


Complete source code can be found here

View original post 17 more words


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s