实体方面(在 Spring 中) [英] Entity Aspect (in Spring)

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

问题描述

我在定义我的方面时遇到了一些问题.我有一堆实体,我想在其中分析 get-methods,所以我编写了以下切入点和方法

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())")

@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.

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

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