我试图在我的代码中配置 promethues,我只需要创建一个如下所示的 bean。我在想春天是怎么认出来CollectorRegistry
的。spring 是如何实例化所有必要的变量CollectorRegistry
并设置所有必要的配置的?
@Component
public class TestProm{
public TestProm(CollectorRegistry registry){
// Some initialization code here
}
}
@Bean
但是,当我尝试通过在我的类中定义 a 以另一种方式定义它时@Configuration
,它似乎无法正常工作,因为我自己的构造函数 forCollectorRegistry
没有所有必要的属性。
@Configuration
public class PromConfiguration{
@Bean
public TestProm getTestProm() {
return new TestProm(new CollectorRegistry());
}
}
public class TestProm{
public TestProm(CollectorRegistry registry){
//Some code here
}
}
CollectorRegistry
当我进行客户实现时,如何识别/复制 spring 完成的初始化。