问题描述:
一个上线稳定运行很久了的项目,由于需求变更开发新功能需要引入新的maven依赖,开发过程及windows7中的Tomcat8运行均正常,但是部署至Linux正式环境后调用方法抛出异常,新增 jwt 相关依赖。
异常日志:
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at com.jfinal.aop.Invocation.invoke(Invocation.java:87) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:74) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:74) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:492) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1152) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) 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 com.jfinal.aop.Invocation.invoke(Invocation.java:73) ... 20 more Caused by: java.lang.NoSuchFieldError: USE_DEFAULTS at com.fasterxml.jackson.annotation.JsonInclude$Value.<clinit>(JsonInclude.java:204) at com.fasterxml.jackson.databind.cfg.MapperConfig.<clinit>(MapperConfig.java:44) at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:558) at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:474) at com.auth0.jwt.JWTCreator.<init>(JWTCreator.java:33) at com.auth0.jwt.JWTCreator.<init>(JWTCreator.java:24) at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:311) at com.zhengxin.tools.JwtToken.createToken(JwtToken.java:41) at com.zhengxin.controller.AdminController.getXJDToken(AdminController.java:67) at com.zhengxin.controller.AdminController.login(AdminController.java:50) ... 25 more
解决方案:
根据 java.lang.NoSuchFieldError 异常定位jar冲突 ,通过maven过滤找到所有相关依赖,然后检查部署war中lib的jar,发现jackson-annotations、jackson-core、jackson-databind 的jar存在高低两个版本,按照惯例保留高版本,上线ok,问题解决
参考资料:
https://blog.csdn.net/haifeng_cool/article/details/77196411