Spring Boot NoSuchFieldError:Azure的伴侣,application-insights

dauxcl2d  于 2024-01-06  发布在  Spring
关注(0)|答案(1)|浏览(175)

目前正在迁移我的spring-boot应用程序,以使用最新的兼容版本的JDK 8。我目前收到此错误时,运行spring-boot-app

  1. ightsTelemetryAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'azure.application-insights-com.microsoft.applicationinsights.boot.ApplicationInsightsProperties': Initialization
  2. of bean failed; nested exception is java.lang.NoSuchFieldError: Companion
  3. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:165)
  4. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577)
  5. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
  6. at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731)
  7. at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
  8. at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
  9. at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:175)
  10. at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:155)
  11. at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:97)
  12. at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:174)
  13. at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5218)
  14. at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
  15. at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:753)
  16. at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:727)
  17. at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:695)
  18. at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1016)
  19. at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1903)
  20. at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
  21. at java.util.concurrent.FutureTask.run(FutureTask.java:266)
  22. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  23. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  24. at java.lang.Thread.run(Thread.java:750)
  25. Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webRequestTrackingFilterRegistrationBean' defined in class path resource [com/microsoft/applicationinsights/boot/ApplicationInsightsWebMvcAutoConfiguration.class]: Unsatisfied dependency expressed through method
  26. 'webRequestTrackingFilterRegistrationBean' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.microsoft.applicationinsights.boot.ApplicationInsightsTelemetryAutoConfiguration': Unsatisfied dependency expressed through constructor paramet
  27. er 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'azure.application-insights-com.microsoft.applicationinsights.boot.ApplicationInsightsProperties': Initialization of bean failed; nested exception is java.lang.NoSuchFieldError: Companion
  28. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
  29. at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541)
  30. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
  31. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
  32. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
  33. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
  34. at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
  35. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)

字符串
我的applicationinsights版本是spring-boot-starter-parent 2.7.12,spring-cloud-dependencies 2021.0.3和spring-cloud-starter-bootstrap。我更新到了applicationinsights的最新版本,但仍然收到同样的错误。

  1. <dependency>
  2. <groupId>com.microsoft.azure</groupId>
  3. <artifactId>applicationinsights-spring-boot-starter</artifactId>
  4. <version>2.6.4</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>com.microsoft.azure</groupId>
  8. <artifactId>applicationinsights-logging-logback</artifactId>
  9. <version>2.6.4</version>
  10. </dependency>


我更新了以下工件,还添加了spring-cloud-starter-bootstrap依赖项
| 伪影|先前版本|更新版本|
| --|--|--|
| Spring Boot启动器父母| 2.2.4.RELEASE |2.7.12|
| spring-cloud-dependency| Finchley.M9 |2021.0.3|
| applicationinsights-spring-boot-starter| 1.0.0-BETA |2.6.4|
| 应用程序洞察日志|2.1.1| 2.6.4|

2ledvvac

2ledvvac1#

该错误似乎是由于azure.application-insights-com.microsoft.applicationinsights.boot.ApplicationInsightsProperties bean的初始化(或)由于Azure Application Insights包和您正在使用的Sping Boot 之间的版本不兼容而发生的。
尝试升级/降级与您的 *Sping Boot 版本 * 兼容的 *Azure Application Insights库版本 *。
(或)

  • 使用Sping Boot 2.7.x版本创建应用程序,以使用ApplicationInsights包2.6.4版本。*

升级版本后运行mvn clean install
x1c 0d1x的数据

备选案文:

  • AFAIK,applicationinsights-spring-boot-starter软件包用于配置Application Insights的旧方法。
  • 相反,您可以在应用程序中使用Java Agent/applicationinsights-runtime-attach来配置AppInsights。
  1. <dependency>
  2. <groupId>com.microsoft.azure</groupId>
  3. <artifactId>applicationinsights-runtime-attach</artifactId>
  4. <version>3.4.14</version>
  5. </dependency>

字符串

pom.xml:

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-web</artifactId>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.springframework.boot</groupId>
  8. <artifactId>spring-boot-starter-tomcat</artifactId>
  9. <scope>provided</scope>
  10. </dependency>
  11. <dependency>
  12. <groupId>org.apache.tomcat.embed</groupId>
  13. <artifactId>tomcat-embed-jasper</artifactId>
  14. <scope>provided</scope>
  15. </dependency>
  16. <dependency>
  17. <groupId>com.microsoft.azure</groupId>
  18. <artifactId>applicationinsights-runtime-attach</artifactId>
  19. <version>3.4.14</version>
  20. </dependency>
  21. </dependencies>


src>main>resources文件夹下创建applicationinsights-dev.json并添加:

  1. {
  2. "connectionString":"InstrumentationKey=XXXXX;IngestionEndpoint=https://XXXXXX.in.applicationinsights.azure.com/;LiveEndpoint=https://XXXXX.livediagnostics.monitor.azure.com/"
  3. }


applications.properties中添加以下配置:

  1. -Dapplicationinsights:
  2. runtime-attach:
  3. configuration:
  4. classpath:
  5. file: "applicationinsights-dev.json"

**main()

  1. package com.javabycode.springboot;
  2. import com.microsoft.applicationinsights.attach.ApplicationInsights;
  3. import org.springframework.boot.SpringApplication;
  4. @SpringBootApplication
  5. public class MyWebApplication{
  6. public static void main(String[] args) throws Exception {
  7. ApplicationInsights.attach();
  8. SpringApplication.run(MyWebApplication.class, args);
  9. }
  10. }

参考资料:

Upgrading from 2.x - Azure Monitor Application Insights Java - Azure Monitor | Microsoft LearnConfigure Azure Monitor Application Insights for Spring Boot - Azure Monitor | Microsoft Learn

展开查看全部

相关问题