Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

469
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda