当前位置:  开发笔记 > 编程语言 > 正文

错误"java.lang.NoSuchFieldError:WRITE_DURATIONS_AS_TIMESTAMPS"

如何解决《错误"java.lang.NoSuchFieldError:WRITE_DURATIONS_AS_TIMESTAMPS"》经验,为你挑选了1个好方法。

我正在使用Maven开发Java Web Service,这取决于另一个java项目.我将调用Web服务项目(项目2)和依赖项目(项目1)

所以我有一个"项目1"这个项目使用"com.fasterxml.jackson.datatype.joda.JodaModule"jar."项目1"具有此依赖性.


    
        com.google.guava
        guava
        19.0-rc2
    
    
        commons-lang
        commons-lang
        2.6
    
    
        org.slf4j
        slf4j-api
        1.7.12
    
    
        joda-time
        joda-time
        2.8.2
    
    
        org.apache.httpcomponents
        httpclient
        4.5.1
    
    
        com.fasterxml.jackson.core
        jackson-core
        2.6.2
    
    
        com.fasterxml.jackson.core
        jackson-annotations
        2.6.2
    
    
        com.fasterxml.jackson.core
        jackson-databind
        2.6.2
    
    
        com.fasterxml.jackson.datatype
        jackson-datatype-joda
        2.6.2
    
    
        com.google.code.findbugs
        jsr305
        3.0.0
        provided
    
    
        junit
        junit
        4.12
        test
    
    
        org.powermock
        powermock-module-junit4
        ${powermock.version}
        test
    
    
        org.powermock
        powermock-api-mockito
        ${powermock.version}
        test
    
    
        org.skyscreamer
        jsonassert
        1.2.3
        test
    
    
        com.yammer.dropwizard
        dropwizard-testing
        0.6.2
        test
    

现在我需要在"项目2"中使用"项目1".所以我写了这段代码

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

    ObjectMapper mapper = new ObjectMapper();
    mapper.setDateFormat(new ISO8601DateFormat());
    mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
    JodaModule module = new JodaModule();
    mapper.registerModule(module);

}

但是当我从客户那里打电话给邮报时.它给了我这个错误.

Warning:   StandardWrapperValve[Recieve]: Servlet.service() for servlet Recieve threw exception
java.lang.NoSuchFieldError: WRITE_DURATIONS_AS_TIMESTAMPS
    at com.fasterxml.jackson.datatype.joda.ser.DurationSerializer.(DurationSerializer.java:28)
    at com.fasterxml.jackson.datatype.joda.ser.DurationSerializer.(DurationSerializer.java:25)
    at com.fasterxml.jackson.datatype.joda.JodaModule.(JodaModule.java:45)
    at Recieve.doPost(Recieve.java:82)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)

注意:我在Maven Java Project而不是Maven Web Java Project中尝试相同的代码,它在Maven java项目中工作.

public class test {

public static void main(String[] args) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setDateFormat(new ISO8601DateFormat());
    mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
    JodaModule module = new JodaModule();
    mapper.registerModule(module);
    }
}

编辑1:

我正在研究glassfish 4.1,当我将服务器更改为tomcat时,它可以工作.所以我认为glassfish中存在冲突罐子.但到现在为止我不知道如何解决这场冲突.



1> Gergely Bacs..:

这是由jackson libs和joda之间的依赖性不匹配引起的.当仅使用原始Maven模块时,它正在为您工作,因为它将所有jackson库声明为2.6.2,这是正确的.你的封闭webapp肯定使用另一个杰克逊版本作为直接或传递依赖.这会导致类似路径上存在不兼容的jar.

要验证:只需检查您的WEB-INF/lib并查找与jackson相关的所有库.你会发现非2.6.2版本的.

要修复:您需要决定是否能够在Web应用程序上升级到新版本.然后相应地配置Maven依赖项.

推荐阅读
家具销售_903
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有