com.amazonaws.transform.JsonErrorUnmarshaller:方法<init>(Ljava / lang / Class;)找不到V

时间:2016-06-03 16:06:39

标签: java amazon-web-services logback amazon-cloudwatch amazon-cloudwatchlogs

我们使用名为logback-ext-cloudwatch-appender的库将基于logback的日志发送到AWS Cloudwatch。这就是我们的pom.xml文件中的依赖项。

    <dependency>
        <groupId>org.eluder.logback</groupId>
        <artifactId>logback-ext-cloudwatch-appender</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>

几天前,这些错误开始出现在我们的日志中。

java.lang.NoSuchMethodError: com.amazonaws.transform.JsonErrorUnmarshaller: method <init>(Ljava/lang/Class;)V not found
    at com.amazonaws.services.logs.model.transform.InvalidParameterExceptionUnmarshaller.<init>(InvalidParameterExceptionUnmarshaller.java:26)
    at com.amazonaws.services.logs.AWSLogsClient.init(AWSLogsClient.java:280)
    at com.amazonaws.services.logs.AWSLogsClient.<init>(AWSLogsClient.java:275)
    at com.amazonaws.services.logs.AWSLogsClient.<init>(AWSLogsClient.java:248)
    at org.eluder.logback.ext.cloudwatch.appender.AbstractCloudWatchAppender.doStart(AbstractCloudWatchAppender.java:100)
    at org.eluder.logback.ext.aws.core.AbstractAwsEncodingStringAppender.start(AbstractAwsEncodingStringAppender.java:123)
    at org.eluder.logback.ext.cloudwatch.appender.AbstractCloudWatchAppender.start(AbstractCloudWatchAppender.java:95)
    at ch.qos.logback.ext.spring.DelegatingLogbackAppender.getDelegate(Unknown Source)
    at ch.qos.logback.ext.spring.DelegatingLogbackAppender.append(Unknown Source)
    at ch.qos.logback.ext.spring.DelegatingLogbackAppender.append(Unknown Source)
    at ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:84)
    at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:48)
    at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:270)
    at ch.qos.logback.classic.Logger.callAppenders(Logger.java:257)
    at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:421)
    at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
    at ch.qos.logback.classic.Logger.info(Logger.java:579)
    (truncated)

我发现我们已升级到AWS 1.11.5,但在该版本中找不到任何此类错误的证据。

1 个答案:

答案 0 :(得分:3)

事实证明,当前版本的logback-ext-cloudwatch-appender对特定版本的aws-java-sdk-logs 1.10.2具有传递依赖性,这与兼容其他aws-java-sdk库1.11.0及以上版本。我们确实使用了许多其他aws-java-sdk库。我们排除了这样的依赖。

<dependency>
    <groupId>org.eluder.logback</groupId>
    <artifactId>logback-ext-cloudwatch-appender</artifactId>
    <version>1.0-SNAPSHOT</version>
    <exclusions>
        <exclusion>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-core</artifactId>
        </exclusion>
        <exclusion>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-logs</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-core</artifactId>
    <version>1.11.5</version>
</dependency>
<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-logs</artifactId>
    <version>1.11.5</version>
</dependency>

此时我们开始收到另一个错误。

 Exception in thread "org.myorg.task.MyTask working" java.lang.NoSuchMethodError: com.amazonaws.services.logs.AWSLogsClient.createLogGroup(Lcom/amazonaws/services/logs/model/CreateLogGroupRequest;)V
         at org.eluder.logback.ext.cloudwatch.appender.AbstractCloudWatchAppender.createLogGroup(AbstractCloudWatchAppender.java:171)
         at org.eluder.logback.ext.cloudwatch.appender.AbstractCloudWatchAppender.doStart(AbstractCloudWatchAppender.java:107)
         at org.eluder.logback.ext.aws.core.AbstractAwsEncodingStringAppender.start(AbstractAwsEncodingStringAppender.java:123)
         at org.eluder.logback.ext.cloudwatch.appender.AbstractCloudWatchAppender.start(AbstractCloudWatchAppender.java:95)
         at ch.qos.logback.core.joran.action.AppenderAction.end(AppenderAction.java:90)
         at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:309)
         at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:193)
         at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:179)
         at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:62)
         at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:155)
         at ch.qos.logback.core.sift.SiftingJoranConfiguratorBase.doConfigure(SiftingJoranConfiguratorBase.java:82)
         at ch.qos.logback.core.sift.AbstractAppenderFactoryUsingJoran.buildAppender(AbstractAppenderFactoryUsingJoran.java:51)
         at ch.qos.logback.core.sift.AppenderTracker.buildComponent(AppenderTracker.java:56)
         at ch.qos.logback.core.sift.AppenderTracker.buildComponent(AppenderTracker.java:32)
         at ch.qos.logback.core.spi.AbstractComponentTracker.getOrCreate(AbstractComponentTracker.java:124)
         at ch.qos.logback.core.sift.SiftingAppenderBase.append(SiftingAppenderBase.java:104)
         at ch.qos.logback.core.AppenderBase.doAppend(AppenderBase.java:82)
         at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:48)
         at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:270)
         at ch.qos.logback.classic.Logger.callAppenders(Logger.java:257)
         at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:421)
         at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
         at ch.qos.logback.classic.Logger.info(Logger.java:579)

仅仅排除依赖项不起作用。我不得不分叉并重建logback-ext-cloudwatch-appender jar,它依赖于当前的1.11.5 aws-java-sdk库。尝试将新的AWS依赖项与针对旧库构建的logback-ext-cloudwatch-appender jar一起使用会导致createLogGroup的方法签名(返回类型)不匹配,从而导致运行时错误。为了让它运行,我只需要在我的分叉版本中更改pom.xml文件,而不是源代码。