@AspectJ or XML for Spring AOP?

If you have chosen to use Spring AOP, then you have a choice of @AspectJ or XML style. There are various pros and cons to consider.@AspectJ is best to use.

The XML style will be most familiar to existing spring users and it is backed by genuine POJOs.

The XML style has two disadvantages.

  • Firstly it does not fully encapsulate the implementation of the requirement it addresses in a single place. When using the XML style, the knowledge of how a requirement is implemented is split across the declaration of the backing bean class, and the XML in the configuration file.

    When using the @AspectJ style there is a single module - the aspect - in which this information is encapsulated.

  • Secondly, the XML style is slightly more limited in what it can express than the @AspectJ style: it is not possible to combine named pointcuts declared in XML.

For example, in the @AspectJ style you can write logic something like below:

After seeing all execution of AOP we are in a position of summarizing advantages if AOP.


The crosscutting concern is a concern which is applicable throughout the application and it affects the entire application. For example: logging, security and data transfer are the concerns which are needed in almost every module of an application, hence they are cross-cutting concerns.