更新 NewRelic 版本在运行时抛出 AbstractMethodError

Updating NewRelic version throwing AbstractMethodError at runtime

我正在将项目中的 newrelic 版本从 2.x.x 更新到 5.x.x。我按照 newrelic 文档中提到的步骤进行操作(我更新了 pom 文件中的依赖版本,更新了代理 jar 文件和配置文件)。

但现在 运行 项目通过了所需的 java 代理:

java -server -javaagent:/Users/amit.upadhyay/abcproject/abcproject-app/newrelic-stage/newrelic.jar -jar abcproject-app/target/abcproject-app-*.*.*-SNAPSHOT.jar /Users/amit.upadhyay/Downloads/abcproject.yml

我得到 java.lang.AbstractMethodError。以下是错误日志:

ERROR StatusLogger Caught java.lang.AbstractMethodError setting feature http://xml.org/sax/features/external-general-entities to false on DocumentBuilderFactory org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@e320068: java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V   at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.setFeature(XmlConfiguration.java:212)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.disableDtdProcessing(XmlConfiguration.java:205)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.newDocumentBuilder(XmlConfiguration.java:194)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.<init>(XmlConfiguration.java:92)   at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getConfiguration(XmlConfigurationFactory.java:46)   at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:420)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:347)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:261)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:616)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:637)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:243)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)   at com.newrelic.agent.deps.org.apache.logging.log4j.LogManager.getContext(LogManager.java:174)  at com.newrelic.agent.deps.org.apache.logging.log4j.LogManager.getLogger(LogManager.java:648)   at com.newrelic.agent.logging.Log4jLogger.<init>(Log4jLogger.java:68)   at com.newrelic.agent.logging.Log4jLogger.create(Log4jLogger.java:415)  at com.newrelic.agent.logging.Log4jLogManager.createRootLogger(Log4jLogManager.java:38)     at com.newrelic.agent.logging.Log4jLogManager.initializeRootLogger(Log4jLogManager.java:98)     at com.newrelic.agent.logging.Log4jLogManager.<init>(Log4jLogManager.java:34)   at com.newrelic.agent.logging.Log4jLogManager.create(Log4jLogManager.java:254)  at com.newrelic.agent.logging.AgentLogManager.createAgentLogManager(AgentLogManager.java:19)    at com.newrelic.agent.logging.AgentLogManager.<clinit>(AgentLogManager.java:9)  at com.newrelic.agent.Agent.<clinit>(Agent.java:59)     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 com.newrelic.bootstrap.BootstrapAgent.startAgent(BootstrapAgent.java:179)    at com.newrelic.bootstrap.BootstrapAgent.premain(BootstrapAgent.java:81)    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 sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)  at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401) ERROR StatusLogger Caught java.lang.AbstractMethodError setting feature http://xml.org/sax/features/external-parameter-entities to false on DocumentBuilderFactory org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@e320068: java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V     at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.setFeature(XmlConfiguration.java:212)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.disableDtdProcessing(XmlConfiguration.java:206)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.newDocumentBuilder(XmlConfiguration.java:194)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.<init>(XmlConfiguration.java:92)   at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getConfiguration(XmlConfigurationFactory.java:46)   at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:420)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:347)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:261)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:616)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:637)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:243)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)   at com.newrelic.agent.deps.org.apache.logging.log4j.LogManager.getContext(LogManager.java:174)  at com.newrelic.agent.deps.org.apache.logging.log4j.LogManager.getLogger(LogManager.java:648)   at com.newrelic.agent.logging.Log4jLogger.<init>(Log4jLogger.java:68)   at com.newrelic.agent.logging.Log4jLogger.create(Log4jLogger.java:415)  at com.newrelic.agent.logging.Log4jLogManager.createRootLogger(Log4jLogManager.java:38)     at com.newrelic.agent.logging.Log4jLogManager.initializeRootLogger(Log4jLogManager.java:98)     at com.newrelic.agent.logging.Log4jLogManager.<init>(Log4jLogManager.java:34)   at com.newrelic.agent.logging.Log4jLogManager.create(Log4jLogManager.java:254)  at com.newrelic.agent.logging.AgentLogManager.createAgentLogManager(AgentLogManager.java:19)    at com.newrelic.agent.logging.AgentLogManager.<clinit>(AgentLogManager.java:9)  at com.newrelic.agent.Agent.<clinit>(Agent.java:59)     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 com.newrelic.bootstrap.BootstrapAgent.startAgent(BootstrapAgent.java:179)    at com.newrelic.bootstrap.BootstrapAgent.premain(BootstrapAgent.java:81)    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 sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)  at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401) ERROR StatusLogger Caught java.lang.AbstractMethodError setting feature http://apache.org/xml/features/nonvalidating/load-external-dtd to false on DocumentBuilderFactory org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@e320068: java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V  at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.setFeature(XmlConfiguration.java:212)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.disableDtdProcessing(XmlConfiguration.java:207)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.newDocumentBuilder(XmlConfiguration.java:194)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.<init>(XmlConfiguration.java:92)   at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getConfiguration(XmlConfigurationFactory.java:46)   at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:420)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:347)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:261)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:616)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:637)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:243)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)   at com.newrelic.agent.deps.org.apache.logging.log4j.LogManager.getContext(LogManager.java:174)  at com.newrelic.agent.deps.org.apache.logging.log4j.LogManager.getLogger(LogManager.java:648)   at com.newrelic.agent.logging.Log4jLogger.<init>(Log4jLogger.java:68)   at com.newrelic.agent.logging.Log4jLogger.create(Log4jLogger.java:415)  at com.newrelic.agent.logging.Log4jLogManager.createRootLogger(Log4jLogManager.java:38)     at com.newrelic.agent.logging.Log4jLogManager.initializeRootLogger(Log4jLogManager.java:98)     at com.newrelic.agent.logging.Log4jLogManager.<init>(Log4jLogManager.java:34)   at com.newrelic.agent.logging.Log4jLogManager.create(Log4jLogManager.java:254)  at com.newrelic.agent.logging.AgentLogManager.createAgentLogManager(AgentLogManager.java:19)    at com.newrelic.agent.logging.AgentLogManager.<clinit>(AgentLogManager.java:9)  at com.newrelic.agent.Agent.<clinit>(Agent.java:59)     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 com.newrelic.bootstrap.BootstrapAgent.startAgent(BootstrapAgent.java:179)    at com.newrelic.bootstrap.BootstrapAgent.premain(BootstrapAgent.java:81)    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 sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)  at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401) Mar 16, 2020 01:40:38 +0530 [8698 1] com.newrelic INFO: Configuration file not found. The agent will attempt to read required values from environment variables. Mar 16, 2020 01:40:38 +0530 [8698 1] com.newrelic INFO: Using default collector host: collector.newrelic.com Mar 16, 2020 01:40:38 +0530 [8698 1] com.newrelic ERROR: Unable to start the New Relic Agent. Your application will continue to run but it will not be monitored. com.newrelic.agent.config.ConfigurationException: The agent requires an application name. Check the app_name setting in newrelic.yml    at com.newrelic.agent.config.ConfigServiceFactory.validateConfig(ConfigServiceFactory.java:64)  at com.newrelic.agent.config.ConfigServiceFactory.createConfigService(ConfigServiceFactory.java:27)

因为我在运行时遇到 AbstractMethodError,即我在某处使用旧接口,该接口已在新版本的 newrelic java 代理 5.x.x.

中更新

错误日志表明我项目中使用的 xerces 版本与更新的 newrelic java 代理中的版本存在冲突。在谷歌搜索中,我发现这两个 SO 链接 first and second 有类似的问题。根据给出的答案,我添加了

        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.11.0</version>
        </dependency>

        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            <version>1.4.01</version>
        </dependency>

我的 pom 文件,这个 AbstractMethodError 错误消失了。

但是在 运行 上我又开始遇到这个异常:com.newrelic.agent.config.ConfigurationException

此异常的日志是:

Mar 16, 2020 02:37:18 +0530 [9598 1] com.newrelic INFO: Configuration file not found. The agent will attempt to read required values from environment variables.
Mar 16, 2020 02:37:18 +0530 [9598 1] com.newrelic INFO: Using default collector host: collector.newrelic.com
Mar 16, 2020 02:37:18 +0530 [9598 1] com.newrelic ERROR: Unable to start the New Relic Agent. Your application will continue to run but it will not be monitored.
com.newrelic.agent.config.ConfigurationException: The agent requires an application name. Check the app_name setting in newrelic.yml
    at com.newrelic.agent.config.ConfigServiceFactory.validateConfig(ConfigServiceFactory.java:64) ~
    at com.newrelic.agent.config.ConfigServiceFactory.createConfigService(ConfigServiceFactory.java:27) ~
    at com.newrelic.agent.service.ServiceManagerImpl.<init>(ServiceManagerImpl.java:126) ~
    at com.newrelic.agent.Agent.premain(Agent.java:279) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_222]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_222]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_222]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_222]
    at com.newrelic.bootstrap.BootstrapAgent.startAgent(BootstrapAgent.java:179) 
    at com.newrelic.bootstrap.BootstrapAgent.premain(BootstrapAgent.java:81) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_222]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_222]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_222]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_222]
    at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386) [?:1.8.0_222]
    at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401) [?:1.8.0_222]

现在,我不明白为什么会抛出 ConfigurationException(或者为什么找不到配置文件)。与旧版本的 newrelic 代理(2.x.x 或 3.x.x)一起使用时,相同的 java 命令(代理 jar 和配置文件的路径完全相同)运行完美。

我想了解这里发生了什么wrong/missing?

我能够在我的项目中更新到最新的 newrelic 版本。似乎他们已经更新了 java 代理中的 xerces 版本,其中版本大于 5.0.0。随着更新 xerces 版本的修复,我需要将 newrelic 配置文件作为系统属性显式传递以解析 ConfigurationException.

总体总结: - 将这些库更新为

        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.11.0</version>
        </dependency>

        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            <version>1.4.01</version>
        </dependency>

并将 newrelic 配置文件作为系统传递 属性:

-Dnewrelic.config.file=./${NEW_RELIC_DIR_NAME}/newrelic.yml