Tomcat部署CAS Overlay与CAS Management时Jackson冲突致启动故障
问题背景
- 已完成Tomcat 9.0.41运行环境搭建
- 先构建cas-overlay-template 6.3项目,将生成的cas.war放入Tomcat的webapps目录启动,所有功能运行正常
- 后续构建cas-management-overlay 6.3项目,将生成的cas-management.war放入同一webapps目录,重启Tomcat加载应用时启动失败
完整报错日志
2021-01-22 20:39:04,641 WARN [org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext] - <Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'formContentFilter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedFormContentFilter]: Factory method 'formContentFilter' threw exception; nested exception is java.lang.NoSuchMethodError: 'com.fasterxml.jackson.databind.cfg.MutableCoercionConfig com.fasterxml.jackson.dataformat.xml.XmlMapper.coercionConfigDefaults()'> 2021-01-22 20:39:04,666 ERROR [org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter] - < *************************** APPLICATION FAILED TO START *************************** Description: An attempt was made to call a method that does not exist. The attempt was made from the following location: com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:175) The following method did not exist: 'com.fasterxml.jackson.databind.cfg.MutableCoercionConfig com.fasterxml.jackson.dataformat.xml.XmlMapper.coercionConfigDefaults()' The method's class, com.fasterxml.jackson.dataformat.xml.XmlMapper, is available from the following locations: jar:file:/opt/cas/tomcat-9.0.41/webapps/cas-management/WEB-INF/lib/jackson-dataformat-xml-2.12.0.jar!/com/fasterxml/jackson/dataformat/xml/XmlMapper.class The class hierarchy was loaded from the following locations: com.fasterxml.jackson.dataformat.xml.XmlMapper: file:/opt/cas/tomcat-9.0.41/webapps/cas-management/WEB-INF/lib/jackson-dataformat-xml-2.12.0.jar com.fasterxml.jackson.databind.ObjectMapper: file:/opt/cas/tomcat-9.0.41/webapps/cas-management/WEB-INF/lib/jackson-databind-2.11.3.jar com.fasterxml.jackson.core.ObjectCodec: file:/opt/cas/tomcat-9.0.41/webapps/cas-management/WEB-INF/lib/jackson-core-2.11.3.jar com.fasterxml.jackson.core.TreeCodec: file:/opt/cas/tomcat-9.0.41/webapps/cas-management/WEB-INF/lib/jackson-core-2.11.3.jar Action: Correct the classpath of your application so that it contains a single, compatible version of com.fasterxml.jackson.dataformat.xml.XmlMapper
问题根因
- 报错本质是Jackson生态组件的版本错位不兼容:
- 位于
cas-management/WEB-INF/lib目录下的jackson-dataformat-xml-2.12.0.jar,其内部的XmlMapper初始化逻辑需要调用jackson-databind 2.12.x版本才新增的coercionConfigDefaults()方法 - 但同目录下实际加载的
jackson-databind、jackson-core版本为2.11.3,不存在上述新增方法,最终触发NoSuchMethodError导致应用启动失败
- 位于
- 已部署的cas主应用不受影响的原因:Tomcat对每个web应用采用独立类加载隔离机制,cas应用本身的Jackson依赖版本是自洽兼容的,不会和cas-management的依赖版本产生交叉干扰
修复操作步骤
- 优先方案:在cas-management-overlay项目的构建配置中,强制统一所有Jackson相关组件的版本,与已存在的
jackson-dataformat-xml-2.12.0.jar对齐,将jackson-databind、jackson-core、jackson-annotations的版本全部锁定为2.12.0,重新构建生成war包后重新部署 - 临时快速修复方案:无需重新构建项目,直接将
cas-management/WEB-INF/lib目录下的jackson-dataformat-xml-2.12.0.jar替换为2.11.3版本,与目录内现有jackson-databind、jackson-core的版本完全对齐,替换完成后重启Tomcat即可 - 操作注意事项:
- 所有依赖版本调整操作,必须限定在对应web应用的
WEB-INF/lib目录内完成 - 不要将调整后的Jar包放入Tomcat公共lib目录,避免跨应用类加载冲突
- 所有依赖版本调整操作,必须限定在对应web应用的
内容的提问来源于stack exchange,提问作者Tch
相关产品推荐
相关产品推荐

