Results 1 to 3 of 3

Thread: Implementing custom aspect recommendation

Hybrid View

  1. #1
    Join Date
    Oct 2011
    Posts
    5

    Default Implementing custom aspect recommendation

    Hi, let me first greet anyone as this is my first post on this forum.

    It is probably one of the most worn-out questions spring aop - the logging aspect.

    I need to create logging aspect which will simply log input parameters of methods and optionally time of method execution really nothing else.

    The primary aim is to avoid other developers need to change code of existing apps, so xml configured aspects seems as number one choice.

    Now, I was checking out Spring 2.x and 3.x AOP API and as I've seen, if I use Spring 3 AOP annotation based aspects those will be
    coupled with one particular application (package as I can't make pointcuts to be configurable as it is possible with xml configured aspects.

    To me, if I want to package aspect classes in separate module and reuse it in different apps, the most viable solution is implementing
    spring aop interfaces (MethodBeforeAdvice etc) and then simply add aspects/advices into app context configuration file,
    where it could be configured with desired pointcuts.

    Perhaps my findings are wrong, maybe there is some other, better, approach?

    Any suggestion/info/advice is welcome and appreaciated.

    Thanks in advance

  2. #2
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    I'd definitely go with annotations. They have the great advantage that they decouple you from the AOP implementation strategy. Say one day you decide that Spring AOP doesn't meet your growing needs, just change one configuration row in xml, activate the weaver agent and you can use AspectJ without changing anything else...this wouldn't be possible if you used xml config. About your concerns...

    The primary aim is to avoid other developers need to change code of existing apps, so xml configured aspects seems as number one choice.
    I don't understand why you say that. AOP is all about not changing existing code, and you get that functionality both using xml and annotation strategy.

    if I use Spring 3 AOP annotation based aspects those will be
    coupled with one particular application (package as I can't make pointcuts to be configurable as it is possible with xml configured aspects.
    And what is the difference between changing a Spring xml file and a class? In both cases, you would need to redeploy the application so that the new poincuts become active (the new proxies are created at application bootstrap). Also, you can externalize your pointcut configuration in properties files and then read them for your pointcut annotations.

    However, if you feel you are better off with xml config, then go for it...there is nothing wrong with that either (except, as I said, you don't get to switch to AspectJ so easily as you would do with annotations...and annotations are cool)

  3. #3
    Join Date
    Oct 2011
    Posts
    5

    Default

    My concern was primarily on configuring pointcuts, I'll give it a try with properties file - thanks for that.

    Now, let me explain more thoroughly. I'd like to do something like this:
    Implement aspects in separate module (jar) and deliver it to web app developer so
    he/she can simply reference it and add aspects in desired way, apply it to desired methods, that is.

    A balanced approach could be going with additional custom annotation with aspect applied to methods tagged with that annotation,
    that way, code changes in existing app would be only tagging methods. Also sounds nice.

    One dev would like to apply it to one set of methods in some package(s), other would like to apply it to another...

    Redeploy is not an issue as sparing development time is primary target, therefore I have had voted for xml primarily.
    Switching in and out aspect frameworks is not what managers are worried about. If they've been asked, they would stick for something forever

    Once again, thanks
    Last edited by rssole; Oct 11th, 2011 at 03:51 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •