无法初始化 class com.amazonaws.partitions.PartitionsLoader

Could not initialize class com.amazonaws.partitions.PartitionsLoader

使用 Eclipse Mars。我已经通过从 help.Now 安装软件添加了 aws java sdk 1.11.123 当我 运行 Tomcat Server 7 我得到这个错误:

May 02, 2017 11:57:32 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [PdsServlet] in context with path [/PdsAWS] threw exception [java.lang.NoClassDefFoundError: Could not initialize class com.amazonaws.partitions.PartitionsLoader] with root cause java.lang.NoClassDefFoundError: Could not initialize class com.amazonaws.partitions.PartitionsLoader

我也得到

java.lang.NoSuchFieldError: ALLOW_FINAL_FIELDS_AS_MUTATORS

但是当我检查图书馆时,我可以看到 PartitionsLoader.How 这可以解决吗?

更多似乎相关的错误:

May 03, 2017 9:39:04 AM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
SEVERE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
java.lang.NoClassDefFoundError: Could not initialize class com.amazonaws.partitions.PartitionsLoader
    at com.amazonaws.regions.RegionMetadataFactory.create(RegionMetadataFactory.java:30)
    at com.amazonaws.regions.RegionUtils.initialize(RegionUtils.java:64)
    at com.amazonaws.regions.RegionUtils.getRegionMetadata(RegionUtils.java:52)
    at com.amazonaws.regions.RegionUtils.getRegion(RegionUtils.java:105)
    at com.amazonaws.services.s3.AmazonS3Client.createSigner(AmazonS3Client.java:3428)
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4156)
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4116)
    at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1700)
    at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1563)
    at com.tradingtechnologies.pdsawssql.aws.s3.S3HealthCheck.put(S3HealthCheck.java:83)
    at com.tradingtechnologies.pdsawssql.aws.s3.S3HealthCheck.put(S3HealthCheck.java:56)
    at com.tradingtechnologies.pdsawssql.aws.s3.S3HealthCheck.execute(S3HealthCheck.java:116)
    at com.tradingtechnologies.pdsawssql.sql.ext.HealthCheck.execute(HealthCheck.java:54)
    at com.tradingtechnologies.pdsservlet.HealthServlet.doGet(HealthServlet.java:31)
    at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory.invoke(JavaMethodInvokerFactory.java:60)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1511)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1442)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at com.tradingtechnologies.pdsservercommon.filters.HttpHeaderFilter.doFilter(HttpHeaderFilter.java:24)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

Tomcat 有自己的依赖文件。可以在 Eclipse 中配置构建路径并且不将依赖项添加到 build/deploy 的 Tomcat,这可能会导致 Java 抛出该错误。

在 Eclipse 中将您的项目重新创建为动态 Web 项目(如果您不熟悉,请查看有关如何操作的文档)。然后在自动生成的 'WEB-INF/lib' 文件夹中包含任何第 3 方 jar 或库,以及从 Eclipse 中的源代码 运行 所需的构建路径(也就是您现在正在做的方式)。然后,当您准备好部署时,导出到 war 文件,'WEB-INF/lib' 文件夹中的所有必要库将对您的编译源可见。

java.lang.NoSuchFieldError: ALLOW_FINAL_FIELDS_AS_MUTATORS

这听起来就像是从某处挑选旧版本的 Jackson。 PartitionsLoader 在初始化静态成员字段时引用 MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS。如果您在运行时选择的 MapperFeature 版本没有此字段,则由此产生的异常将导致 PartitionsLoader 的 class 初始化过程失败。随后尝试引用 class 将抛出您所看到的异常。

ALLOW_FINAL_FIELDS_AS_MUTATORS 是在 2.2 版本中添加的。您选择哪个版本?

好的,我也遇到过同样的依赖地狱挑战,并且花了很长时间来清理。 以下是我的一组依赖项,需要同步 -

  • 经验法则:始终使用相同的 aws sdk 依赖版本(core/s3/ec2 等)
  • 使其他依赖项(由 aws 使用)在您的项目中保持一致。
  • 这包括我的以下内容
    • commons-http 与 AWS 使用的 http-client 冲突
    • 删除 commons-http,使用一致的 http-client 和 http-core 版本
    • 冲突 fasterxml.jackson 库。使用一致的verison使用 噢。
      • 这包括大约 4 个 jar(jackson-databind、核心、注释、cbor

我过去遇到过同样的问题在我的情况下,我像上面那样设置 pom.xml 并解决了问题

  1. set aws-java-sdk-bom

     <repositories>
     <repository>
         <id>mvn2</id>
         <url>http://repo1.maven.org/maven2/</url>
         <releases>
             <enabled>true</enabled>
         </releases>
         <snapshots>
             <enabled>true</enabled>
         </snapshots>
     </repository>
     <repository>
         <id>egovframe</id>
         <url>http://www.egovframe.go.kr/maven/</url>
         <releases>
             <enabled>true</enabled>
         </releases>
         <snapshots>
             <enabled>false</enabled>
         </snapshots>
     </repository>
     <repository>
         <id>egovframe2</id>
         <url>http://maven.egovframe.kr:8080/maven/</url>
         <releases>
             <enabled>true</enabled>
         </releases>
         <snapshots>
             <enabled>false</enabled>
         </snapshots>
     </repository>
    

must set isolate dependencyManagement field and be first field

**<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.amazonaws</groupId>
      <artifactId>aws-java-sdk-bom</artifactId>
      <version>1.11.837</version>
    </dependency>
</dependencies>
</dependencyManagement>**
<dependencies>
    <dependency>
        <groupId>egovframework.rte</groupId>
        <artifactId>egovframework.rte.ptl.mvc</artifactId>
        <version>${egovframework.rte.version}</version>
        <exclusions>
  1. aws-sdk-s3,核心,kms

and set s3, core, kms config in field

<dependencies>
    <dependency>
        <groupId>egovframework.rte</groupId>
        <artifactId>egovframework.rte.ptl.mvc</artifactId>
        <version>${egovframework.rte.version}</version>
        <exclusions>
            <exclusion>

.......

<dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
    </dependency>

    **<dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-core</artifactId>
        <version>1.11.837</version>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-s3</artifactId>
        <version>1.11.837</version>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-kms</artifactId>
            <version>1.11.837</version>
    </dependency>**
</dependencies>