Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

465
Views
AOP for inner and private methods Java

I am trying to log the execution time for methods annotated with custom interface.

I am using Spring AOP.

But this does not seems to work for inner methods.

I think it is the limitation in Spring AOP

@Aspect
public class BusinessProfiler {

  private static Log log = LogFactory.getLog(BusinessProfiler.class);


  @Around("execution(* *(..)) && @annotation(TimeLog)")
  public Object profile(ProceedingJoinPoint point) throws Throwable {
    long start = System.currentTimeMillis();
    Object result = point.proceed();
    String format =
        String.format("%s#%s: took [%s msec]", point.getTarget().getClass().getSimpleName(),
            MethodSignature.class.cast(point.getSignature()).getMethod().getName(),
            System.currentTimeMillis() - start);
    log.info(format);
    return result;
  }

}

Are there any alternatives than Spring AOP

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If you think about the way AOP annotations are dealt with by Spring this will be clear:

Spring takes your class and wraps it in a proxy with the extra code generated on the fly by the AOP annotation added. So only code called via the proxy (i.e from outside your class will be included).

Example

@Service
public class Foo {

  public void doSomething() {
      doSomethingInternal();
  }

  public void doSomethingInternal() {
  }
}

If from another Spring bean I do this:

@Service
public class Bar {

  @Autowired
  private Foo foo;

  public void execute() {
      foo.doSomething();
  }
}

Only doSomething will be called via the proxy which wraps your class, not doSomethingInternal, that will be called by your class.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!