实体方面(春季) [英] Entity Aspect (in Spring)

查看:61
本文介绍了实体方面(春季)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在定义自己的方面时遇到了一些问题.我有一堆想要剖析get方法的实体,所以我写了以下切入点和方法

I'm having a bit of a problem defining my aspects. I've got a bunch of entities that I'd like to profile the get-methods in, so I've written the following pointcut and method

@Pointcut("execution(* tld.myproject.data.entities.*.get*()")
public void getEntityProperty() {}

@Around("getEntityProperty()")
public Object profileGetEntityProperty(ProceedingJoinPoint pjp) throws Throwable {
    long start = System.currentTimeMillis();
    String name = pjp.getSignature().getName();
    Object output = pjp.proceed();
    long elapsedTime = System.currentTimeMillis() - start;
    if(elapsedTime > 100)
        System.err.println("profileGetEntityProperty: Entity method " + name + " execution time: " + elapsedTime + " ms.");
    return output;
}

我已经在配置中启用了编织功能,并且编织到业务层的各个方面都可以正常工作.我的切入点书写正确吗?还是关于实体使它们不可编织? (我的实体在类定义之前以@Entity开头)

I've got weaving turned on in my configuration, and aspects weaving into the business layer work just fine. Is my pointcut correctly written? Or is there something about entities that make them non-weavable? (my entity is prefixed with @Entity before the class definition)

欢呼

尼克

推荐答案

实际上您只是一个括号!

You're only a parenthesis away actually!

@Pointcut("execution(* tld.myproject.data.entities. .get ())")


如果您使用的是Eclipse,我建议您使用AspectJ编译时编织进行开发.这是最简单的方法.


If you're using Eclipse, I will recommend developing with AspectJ compile-time weaving. It's the simplest way.

有了AJDT插件,您将获得很多帮助!我只是粘贴了您的切入点,并遇到了编译错误.添加了括号并成功了!

With the AJDT plugin, you get lots of help! I just pasted in your pointcut and got an compilation error. Added a parenthesis and it worked!

带有AJDT插件的视觉支持的屏幕截图:

Screenshot of visual support with the AJDT plugin:

getHello()方法左侧的橙色箭头表示这是周围建议所建议的.请参见此处以获得更大的示例.

The orange arrow to the left of the getHello() method indicates that is's advised by an around advice. See here for a larger example.

这篇关于实体方面(春季)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆