Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

467
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda