开发者

Using Aspect to annotate methods with @InsightOperation for Spring Insight

I wanted to instrument a large number of classes to use with Spring Insight and instead of adding the @InsightOperation manually to the methods, I wrote an aspect to annotate the methods using point cuts.

However, this is not working. While the manual annotation affects the Spring Insight trace logging, the AspectJ method does not work.

Is there anything I am doing wrong here? (I decompiled the classes after aspectizing and do find the annotation in the class methods)

This is the aspect code snippet:

declare @method :public * com.example.开发者_StackOverflow中文版IExample.execute(..) : @InsightOperation;


Spring documentation says this:

Use of the @Insight* annotations are optional. They make it easy for end users to define custom operation frames and end points without needing to create a plug-in. Because end user code modification is required to use the annotations, they are an option for users who cannot or do not wish to write aspects.

http://static.springsource.com/projects/tc-server/2.5/devedition/htmlsingle/devedition.html

So looks like the only way is to write a custom plugin

http://static.springsource.com/projects/tc-server/2.5/devedition/htmlsingle/devedition.html#tutorial-plugin


It is possible that the Insight LTW does not pick up your introduced annotations. I'll have to dig deeper on that.

In the meantime, you can try a more low-level annotation:

   com.springsource.insight.collection.method.MethodOperationsCollected

If you look at the spring-core plugin, you will see that it does something similar:

  public aspect RepositoryMethodOperationCollectionAspect {
      declare @type: @Repository * : @MethodOperationsCollected;
  }


An easy work around is to call another method from within your aspect method to continue executing the join point. I only tried calling a static method in a static class. See below my code for adding the @InsightOperation to all my JSON serialization.

My aspect:

@Aspect
public class JSONSerializerAspect {

@Around("call(* *.JSONSerializer.serialize(..)) && args(target)")
public Object serialize(ProceedingJoinPoint joinPoint, Object target) throws Throwable {
      return JSONSerializationWrapper.serialize(joinPoint, target);
    }
}

The static class it is calling:

public class JSONSerializationWrapper {

    @InsightOperation(label = "JSON_SERIALIZATION")
    public static Object serialize(ProceedingJoinPoint joinPoint, Object target) throws Throwable {
        return joinPoint.proceed(new Object[]{target});
    }

}

I'm using this myself and tested that it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜