What is AOP? How we can use AOP in SAP Commerce(Hybris) to measure execution time of methods?

Aspect-oriented programming(AOP) is a programming paradigm which breaks down program logic into distinct parts so-called concerns. The key unit of modularity in OOP is the class, whereas in AOP the unit of modularity is the aspect.

Aspects enable the implementation of crosscutting concerns such as- transaction, logging, not central to business logic without cluttering the code core to its functionality. It does so by adding additional behaviour that is the advice to the existing code.

AOP helps to avoid code scattering and duplication due to cross cutting concerns, which aren’t well addressed by OO and give possibility to add new behavior to classes without having to modify their source code.

Common terminologies in AOP:

  • Aspect — module which has a set of APIs providing cross-cutting requirements. It can be normal class configured through XML configuration or through regular classes annotated with @Aspect;

Types of Advice:

  • before — run advice before the a method execution;

How we can use AOP in SAP Commerce(Hybris) to measure execution time of methods?

I will show how we can measure all Prepare interceptors called in SAP Commerce, the same can be done for Populators, Filters and etc.

  1. Create class MethodExecutionTimeAspect

2. Then in your extension-spring.xml define the bean and aop config:


Around advice is a special advice that can control when and if a method is executed. This is true for around advices only, so they require an argument of type ProceedingJoinPoint, whereas other advices just use a plain JoinPoint.

We define the pointcut expression with: <aop:pointcut expression=”execution(

We define the advice with: <aop:around

To measure Populators in your project just replace: expression with:

expression=”execution(public * de.hybris.platform.converters.Populator+.populate(..))”/>

Some more examples with Before and After advices:

Logging after methods execution:

Logging before methods execution:

AOP in SAP Commerce: https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/1808/en-US/8c62d88286691014874bc5b8e7244c7a.html



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store