当前位置: 首页 > 知识库问答 >
问题:

如何使用千分尺Springlegacy运行千分尺弹性?

归浩博
2023-03-14

我对Spring很陌生,正在尝试将我的应用程序连接到麋鹿。该应用程序运行的是Spring boot 1.5.5,因此我使用的是微米遗产。我的pom看起来像这样:

		<dependency>
		  <groupId>io.micrometer</groupId>
		  <artifactId>micrometer-spring-legacy</artifactId>
		  <version>1.3.9</version>
		</dependency>
		<dependency>
		  <groupId>io.micrometer</groupId>
		  <artifactId>micrometer-registry-elastic</artifactId>
		  <version>1.5.1</version>
		</dependency>

每当我尝试启动我的应用程序时,我都会收到以下错误:

    2020-06-19 13:38:29 [ WARN] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded containe
r; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat > [main] org.springframework.boot.context.embedded.AnnotationConfigEm
beddedWebApplicationContext
 2020-06-19 13:38:39 [ INFO]

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. > [main] org.springframework.boot.autoconfigure.logging.AutoConfigurationReport
LoggingInitializer
 2020-06-19 13:38:39 [ERROR] Application startup failed > [main] org.springframework.boot.SpringApplication
 org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to
start embedded Tomcat
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
        at org.apache.camel.spring.boot.FatJarRouter.main(FatJarRouter.java:26)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:595)
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:138)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:87)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:554)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:179)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134)
        ... 14 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMetricsFilter' defined in class path resource [io/micrometer/spring/autoconfigure/web/serv
let/WebMvcMetricsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'webMetricsFilter' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyExc
eption: Error creating bean with name 'elasticMeterRegistry' defined in class path resource [io/micrometer/spring/autoconfigure/export/elastic/ElasticMetricsExportAutoConfiguration.class]: Unsatisfied
dependency expressed through method 'elasticMeterRegistry' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticConfig' define
d in class path resource [io/micrometer/spring/autoconfigure/export/elastic/ElasticMetricsExportAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang
.IllegalStateException: Failed to introspect bean class [io.micrometer.spring.autoconfigure.export.elastic.ElasticPropertiesConfigAdapter] for persistence metadata: could not find class that it depends
 on
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1178)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1072)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:234)
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:182)
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:177)
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAdaptableBeans(ServletContextInitializerBeans.java:159)
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:80)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getServletContextInitializerBeans(EmbeddedWebApplicationContext.java:241)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.selfInitialize(EmbeddedWebApplicationContext.java:228)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.access$000(EmbeddedWebApplicationContext.java:89)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext$1.onStartup(EmbeddedWebApplicationContext.java:213)
        at org.springframework.boot.context.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:55)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1420)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1410)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticMeterRegistry' defined in class path resource [io/micrometer/spring/autoconfigure/expo
rt/elastic/ElasticMetricsExportAutoConfiguration.class]: Unsatisfied dependency expressed through method 'elasticMeterRegistry' parameter 0; nested exception is org.springframework.beans.factory.BeanCr
eationException: Error creating bean with name 'elasticConfig' defined in class path resource [io/micrometer/spring/autoconfigure/export/elastic/ElasticMetricsExportAutoConfiguration.class]: Post-proce
        at java.lang.Class.getMethods(Class.java:1643)
        at org.springframework.util.ReflectionUtils.findConcreteMethodsOnInterfaces(ReflectionUtils.java:635)
        at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:614)
        at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:489)
        at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.buildPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:431)
        at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:397)
        ... 54 common frames omitted
Caused by: java.lang.ClassNotFoundException: io.micrometer.core.instrument.config.validate.Validated
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
        ... 63 common frames omitted

根本原因似乎是类io.micrometer.core.instrument.config.validate.Validated它似乎没有像它应该的那样出现在包中。对此有什么想法吗?

共有1个答案

穆俊名
2023-03-14

根本原因是千分尺内核的版本不匹配,这是由其他依赖关系造成的。我导入了以下内容

<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-spring-legacy</artifactId>
  <version>1.3.9</version>
</dependency>
<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-elastic</artifactId>
  <version>1.5.1</version>
</dependency>

并遇到上述错误,因为这两个依赖项都包含一个版本的微米芯。在我的例子中,版本1.3.9。所需的类被添加到测微计。版本1.5.x的核心,因此解决方案是在版本1.1.x中显式定义依赖关系

<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-spring-legacy</artifactId>
  <version>1.3.9</version>
</dependency>
<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-elastic</artifactId>
  <version>1.5.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-core -->
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-core</artifactId>
    <version>1.5.1</version>
</dependency>

无论如何,由于套接字超时,应用程序不会启动,但上面的错误已修复。:D迁移到Spring启动 2 可能是一个更快的解决方案。断续器

 类似资料:
  • 假设我有一个应用程序,其中REST API更新产品的价格。 我想使用微米计来公开新价格作为指标。我无法理解微米计留档应该如何完成。 唯一对我有效的DoubleFunction是在我的ProductService中创建一个新方法来返回它的价格。这似乎是我想公开作为指标的每一条数据的开销。 我这里缺少什么?为什么不足以更新Gauge?

  • 我对千分尺的理解仍然相当小,所以我将首先介绍我真正想要实现的目标。 目的 鉴于我在数据库表中有记录,每条记录都包含一个“creation_date”。 给定客户端调用 API 来获取这些记录 我想记录记录记录的访问次数,按其创建日期分组(仅月和年) 示例结果 在过去的6小时内,访问了2021年1月创建的10条记录 在过去的12小时内,访问了2021年2月创建的15条记录 在上周一和上周二之间,访问

  • 是否有任何方法可以测量实用程序如何使用线程池?我已经浏览了代码,但还没有看到任何直接的选项。

  • 我正在利用dogstatsd方法,使用千分尺将指标发送给datadog。我获得了正常的指标,如计数器和计量器,但我无法生成事件。有办法生成datadog事件吗?

  • 我正在尝试使用SSL上带有Elasticsearch的测微计。 我在版本1.8.0中使用测微计,在版本7.16.3和OpenJDK 11.0.2中使用Elasticsearch。 因为我知道不可能使用内置配置(链接),所以我尝试注入一个自定义的HttpUrlConnectionSender,如下面的SecureHttpSender类所示: 我注入了Spring启动,所以我可以应用所需的配置,但我得

  • 这篇题为“测微计:Spring Boot 2的新应用程序度量收集器”的博客文章提到了“维度的重要性”。 但是,它没有包括如何在Spring Boot应用程序中设置关联标签的足够示例。 现在,我正在使用Spring Boot 2的千分尺接口来提供Prometheus就绪输出,而无需进行任何基于Java的配置。例如,设置“主机”标签是否需要我编写一些代码?那会是什么样子? 以下是我的整个配置: