Aspect of an object (in Spring)

I have a problem with my aspects. I have a bunch of entities that I would like to profile get-methods, so I wrote 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;
}

I have weaving included in my configuration, and aspects woven into the business layer work very well. Is my pointcut spelled correctly? Or is there something about entities that make them inappropriate? (my entity with the @Entity prefix before the class definition)

Greetings

Nick

+3
source share
3 answers

In fact, you are just brackets!

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


Eclipse, AspectJ . .

AJDT ! pointcut . ​​, !

AJDT:

alt text

getHello() , . . .

+5

, . , new, , , spring.

, ( <context:load-time-weaver/>) @Configurable.

. , , . persistence Hibernate, - - . , .

+1

, @Configurable . @Configurable , "" Hibernate. , . , , unit test "" , ( ehcache) NPE autwired. ; , , .:) . , .

0
source

Source: https://habr.com/ru/post/1747140/


All Articles