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

dauxcl2d  于 5个月前  发布在  Spring
关注(0)|答案(1)|浏览(65)

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

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
 of bean failed; nested exception is java.lang.NoSuchFieldError: Companion
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:165)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
        at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:175)
        at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:155)
        at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:97)
        at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:174)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5218)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:753)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:727)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:695)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1016)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1903)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        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:750)
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
'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
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
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
        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的最新版本,但仍然收到同样的错误。

<dependency>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>applicationinsights-spring-boot-starter</artifactId>
                <version>2.6.4</version>
            </dependency>
            <dependency>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>applicationinsights-logging-logback</artifactId>
                <version>2.6.4</version>
            </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。
<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>applicationinsights-runtime-attach</artifactId>
    <version>3.4.14</version>
</dependency>

字符串

pom.xml:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>applicationinsights-runtime-attach</artifactId>
            <version>3.4.14</version>
        </dependency>
    </dependencies>


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

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


applications.properties中添加以下配置:

-Dapplicationinsights:
runtime-attach:
configuration:
classpath:
file: "applicationinsights-dev.json"

**main()

package  com.javabycode.springboot;
import  com.microsoft.applicationinsights.attach.ApplicationInsights;
import  org.springframework.boot.SpringApplication;

@SpringBootApplication
public  class  MyWebApplication{

public  static  void  main(String[] args) throws  Exception {

ApplicationInsights.attach();

SpringApplication.run(MyWebApplication.class, args);

}

}

参考资料:

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

相关问题