Alex Kravits
Alex Kravits

Reputation: 13

Spring AOP with aspectj annotation

I am sorry that my question is little bit silly, but i need to understand, i am trying to write a logger based on spring aop, i know that there are several realizations, like xml based schema or aspectj annotations, in case i prefer an aspectj annotations does it means that i dont need a xml configuration file at all? I have read many tutorials and examples ones were with xml while another ones were not, now i have messed up with it, can some one give a good explanation for a newbie or mare a ref? Thank you.

Upvotes: 0

Views: 684

Answers (1)

Niall Thomson
Niall Thomson

Reputation: 799

If you're referring to using AspectJ annotations with Spring AOP then you will need a bit of XML configuration on the Spring side but can mostly manage the aspects with annotations. The XML configuration you will need is to at least:

  1. Turn on AOP auto-proxy with <aop:aspectj-autoproxy/>
  2. Use Spring component scan to find your annotated aspects with <context:component-scan base-package="package.of.some.aspect" />

An example can be found here

You should note there are several limitations with how AspectJ annotations apply with respect to Spring AOP, which can be found in the Spring documentation

Upvotes: 2

Related Questions