Open hengyunabc opened 9 years ago
I'm sorry, I don't understand the issue. Can you provide more information?
There are two @Service class: AService, BService.
@Service
public class AService {
@Timed
public void aaa(){
System.err.println("aaa");
}
@Service
public class BService {
@Timed
public void bbb(){
System.err.println("bbb");
}
They both work fine.
If I use AService in other spring bean, like:
@Service
public class CService {
@Autowired
AService aService;
}
The @Timed annotation in AService do not work! In my project, CService is complex, not like the above example.
I found that, when spring create AService, beanPostProcessors do not contains com.ryantenney.metrics.spring.AdvisingBeanPostProcessor
org.springframework.beans.factory.support.AbstractBeanFactory
/** BeanPostProcessors to apply in createBean */
private final List<BeanPostProcessor> beanPostProcessors = new ArrayList<BeanPostProcessor>();
beanPostProcessors only have these BeanPostProcessor.
com.ryantenney.metrics.spring.GaugeFieldAnnotationBeanPostProcessor@30162afc,
com.ryantenney.metrics.spring.GaugeMethodAnnotationBeanPostProcessor@45d3ce31,
com.ryantenney.metrics.spring.CachedGaugeAnnotationBeanPostProcessor@7e6ffca9,
com.ryantenney.metrics.spring.MetricAnnotationBeanPostProcessor@310cae79,
com.ryantenney.metrics.spring.HealthCheckBeanPostProcessor@304c336e
When spring create BService, beanPostProcessors has 4 AdvisingBeanPostProcessor.
com.ryantenney.metrics.spring.GaugeFieldAnnotationBeanPostProcessor@30162afc,
com.ryantenney.metrics.spring.GaugeMethodAnnotationBeanPostProcessor@45d3ce31,
com.ryantenney.metrics.spring.CachedGaugeAnnotationBeanPostProcessor@7e6ffca9,
com.ryantenney.metrics.spring.MetricAnnotationBeanPostProcessor@310cae79,
com.ryantenney.metrics.spring.HealthCheckBeanPostProcessor@304c336e,
com.ryantenney.metrics.spring.AdvisingBeanPostProcessor@69263d6a,
com.ryantenney.metrics.spring.AdvisingBeanPostProcessor@6aa128ea,
com.ryantenney.metrics.spring.AdvisingBeanPostProcessor@6fa093db,
com.ryantenney.metrics.spring.AdvisingBeanPostProcessor@603cb48f,
org.apache.shiro.spring.web.ShiroFilterFactoryBean@38a9088f,
I try to use Ordered.
class AdvisingBeanPostProcessor implements BeanPostProcessor ,Ordered {
...
@Override
public int getOrder() {
return LOWEST_PRECEDENCE;
}
When spring create AService, beanPostProcessors contains AdvisingBeanPostProcessor, but it cause exception:
its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
You shouldn't be dealing directly with BeanPostProcessors…
I have not dealing directly with BeanPostProcessors. I just debug and try to find out the reason.
I mean that when spring create AService,the spring context has not add AdvisingBeanPostProcessor into beanPostProcessors, so @Timed
annotation in AService do not work.
When spring create BService, the spring context already add AdvisingBeanPostProcessor into beanPostProcessors, so @Timed
annotation in BService works.
I don not know why.
Forgive my poor english, I hope that you can understand what I mean.
I believe I have the same issues, preventing upgrade to anything past 3.1.0. The changes related to deprecating com.ryantenney annotations in favor of com.codahale, along with the associated bean processors, seem to be likely culprits: https://github.com/ryantenney/metrics-spring/commit/577b35bc30b3b7dfc2170b8398b69bad8d181424
Under the same package , I created some Service classes. I found that on some complex Service classes, metrics annotation do not work.
I found that, when spring construct the complex Service classes, the BeanPostProcessors:
When spring constuct the simple Service classes, the BeanPostProcessors:
I have yet to find the specific reason.