1

我刚刚使用 springboot 创建了一个应用程序,使用了 APM 工具的 Elastic APM attacher。当我运行 apm 附加程序时,它会生成错误异常,如下所示。用于生成错误的代码:

    package com.howtodoinjava.demo;
    import org.springframework.boot.SpringApplication;
    import co.elastic.apm.attach.*;
    import org.springframework.boot.autoconfigure.SpringBootApplication;

    @SpringBootApplication 
    public class SpringBootDemoApplication {

        public static void main(String[] args) {
            ElasticApmAttacher.attach();
            SpringApplication.run(SpringBootDemoApplication.class, args);
        }
    }



    ---------------------------------------------------------------------
    IDE: Eclipse
    Spring boot 

    Error exception :
    Exception in thread "main" java.lang.IllegalStateException: Error during attachment using: co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@6debcae2
        at co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:608)
        at co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:268)
        at co.elastic.apm.attach.ElasticApmAttacher.attach(ElasticApmAttacher.java:166)
        at co.elastic.apm.attach.ElasticApmAttacher.attach(ElasticApmAttacher.java:120)
        at co.elastic.apm.attach.ElasticApmAttacher.attach(ElasticApmAttacher.java:77)
        at com.howtodoinjava.demo.SpringBootDemoApplication.main(SpringBootDemoApplication.java:11)
    Caused by: java.lang.reflect.InvocationTargetException
        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 co.elastic.apm.attach.bytebuddy.agent.Attacher.install(Attacher.java:106)
        at co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:603)
        ... 5 more
    Caused by: java.lang.NoSuchMethodError: com.sun.jna.Native.load(Ljava/lang/String;Ljava/lang/Class;Ljava/util/Map;)Lcom/sun/jna/Library;
        at com.sun.jna.platform.win32.Kernel32.<clinit>(Kernel32.java:43)
        at co.elastic.apm.attach.bytebuddy.agent.VirtualMachine$ForHotSpot$Connection$ForJnaWindowsNamedPipe$Factory.connect(VirtualMachine.java:1235)
        at co.elastic.apm.attach.bytebuddy.agent.VirtualMachine$ForHotSpot.attach(VirtualMachine.java:256)
        at co.elastic.apm.attach.bytebuddy.agent.VirtualMachine$ForHotSpot.attach(VirtualMachine.java:239)
        ... 11 more


    ---------------------------

但是,如果我尝试运行应用程序注释行即 //ElasticApmAttacher.attach(); 从相同的代码,它成功运行

    package com.howtodoinjava.demo;

    import org.springframework.boot.SpringApplication;
    import co.elastic.apm.attach.*;
    import org.springframework.boot.autoconfigure.SpringBootApplication;

    @SpringBootApplication 
    public class SpringBootDemoApplication {

        public static void main(String[] args) {
            //ElasticApmAttacher.attach();
            SpringApplication.run(SpringBootDemoApplication.class, args);
        }
    }



      .   ____          _            __ _ _
     /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
    ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
     \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
     =========|_|==============|___/=/_/_/_/
     :: Spring Boot ::        (v1.4.0.RELEASE)

    2019-12-07 22:58:30.086  INFO 16984 --- [           main] c.h.demo.SpringBootDemoApplication       : Starting SpringBootDemoApplication on LP-ArvindK with PID 16984 (C:\Users\arvind.kumar\Downloads\springbootdemo-hello-world-rest\springbootdemo\target\classes started by Arvind.Kumar in C:\Users\arvind.kumar\Downloads\springbootdemo-hello-world-rest\springbootdemo)
    2019-12-07 22:58:30.090  INFO 16984 --- [           main] c.h.demo.SpringBootDemoApplication       : No active profile set, falling back to default profiles: default
    2019-12-07 22:58:30.130  INFO 16984 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@647fd8ce: startup date [Sat Dec 07 22:58:30 IST 2019]; root of context hierarchy
    2019-12-07 22:58:31.046  INFO 16984 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
    2019-12-07 22:58:31.107  INFO 16984 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$64c40b86] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    2019-12-07 22:58:31.431  INFO 16984 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8081 (http)
    2019-12-07 22:58:31.439  INFO 16984 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
    2019-12-07 22:58:31.439  INFO 16984 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.4
    2019-12-07 22:58:31.610  INFO 16984 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
    2019-12-07 22:58:31.610  INFO 16984 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1484 ms
    2019-12-07 22:58:31.734  INFO 16984 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
    2019-12-07 22:58:31.734  INFO 16984 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
    2019-12-07 22:58:31.734  INFO 16984 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
    2019-12-07 22:58:31.734  INFO 16984 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
    2019-12-07 22:58:31.734  INFO 16984 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
    2019-12-07 22:58:32.038  INFO 16984 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
    2019-12-07 22:58:32.050  INFO 16984 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
        name: default
        ...]
    2019-12-07 22:58:32.138  INFO 16984 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.9.Final}
    2019-12-07 22:58:32.142  INFO 16984 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
    2019-12-07 22:58:32.142  INFO 16984 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
    2019-12-07 22:58:32.230  INFO 16984 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
    2019-12-07 22:58:32.350  INFO 16984 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect
    2019-12-07 22:58:32.489  INFO 16984 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
    2019-12-07 22:58:32.489  INFO 16984 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
    2019-12-07 22:58:32.501  INFO 16984 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
    2019-12-07 22:58:32.830  INFO 16984 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@647fd8ce: startup date [Sat Dec 07 22:58:30 IST 2019]; root of context hierarchy
    2019-12-07 22:58:32.878  INFO 16984 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto public java.util.List<com.howtodoinjava.demo.model.Employee> com.howtodoinjava.demo.controller.EmployeeController.getEmployees()
    2019-12-07 22:58:32.878  INFO 16984 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
    2019-12-07 22:58:32.878  INFO 16984 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
    2019-12-07 22:58:32.910  INFO 16984 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
    2019-12-07 22:58:32.910  INFO 16984 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
    2019-12-07 22:58:32.938  INFO 16984 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
    2019-12-07 22:58:33.167  INFO 16984 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
    2019-12-07 22:58:33.205  INFO 16984 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8081 (http)
    2019-12-07 22:58:33.209  INFO 16984 --- [           main] c.h.demo.SpringBootDemoApplication       : Started SpringBootDemoApplication in 3.365 seconds (JVM running for 4.327)

我正在寻找解决方案,但到目前为止一无所知。有人可以建议如何解决它

4

1 回答 1

0

异常来自类的构造,Kernel32该类是 Maven 坐标net.java.dev.jna:jna-platform的类,它本身依赖于net.java.dev.jna:jna。在我看来,您必须在类路径上使用这些依赖项的不兼容版本。

我假设您使用的是 JNA 核心版本 4 和 JNA 平台版本 5。升级第一个或降级后者,错误应该消失。

于 2019-12-08T09:07:43.783 回答