Java 私有方法的Perf4j@profiled注释
我已经为public和private方法添加了Java 私有方法的Perf4j@profiled注释,java,spring,perf4j,Java,Spring,Perf4j,我已经为public和private方法添加了@Profiled注释。我可以看到公共方法的计时日志。但是私有方法没有计时日志 我正确地进行了配置 @Profiled public BigInteger nextPrime() { currentPrime = currentPrime.nextProbablePrime(); return currentPrime; } @Profiled private void test() { try{ Thread.sl
@Profiled
注释。我可以看到公共方法的计时日志。但是私有方法没有计时日志
我正确地进行了配置
@Profiled
public BigInteger nextPrime() {
currentPrime = currentPrime.nextProbablePrime();
return currentPrime;
}
@Profiled
private void test()
{
try{
Thread.sleep(100);
}catch(Exception e)
{
e.printStackTrace();
}
}
是否@profiled annotation仅适用于公共方法?很可能您已使用Spring AOP配置了perf4j,并且由于从同一类内部调用方法时不会调用Spring AOP代理(与使用
测试方法时一样),因此不会记录性能统计信息
查看解释SpringAOP陷阱的博客文章
您的问题的一个解决方案是将AspectJ与perf4j一起使用,因为AspectJ可以处理这种情况。这是Spring AOP的局限性:
使用代理时,应仅将注释应用于
具有公共可见性的方法。如果您对受保护的、私有的
或使用这些注释打包可见方法,不会引发错误,
但是带注释的方法不显示配置的缓存
设置。如果需要的话,考虑使用AspectJ(见下面)
在非公共方法更改字节码本身时对其进行注释。”