IntelliJ IDEA 部署web项目时target目录下jar包冲突问题

项目是一个基于maven的web项目,依赖于公司的核心包。问题是在eclipse下部署成功,但在idea下部署失败。报错如下:

2017-11-16 17:08:28 hrp_mp_scheduler [org.springframework.web.context.ContextLoader.initWebApplicationContext:353] - [ERROR] Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath*:config/kyee-include-all.xml]
Offending resource: class path resource [applicationContext.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:config/core/scheduler.xml]
Offending resource: URL [jar:file:/Users/huangpeng/workspace/tomcat/apache-tomcat-8.0.43/webapps/hrp_mp_scheduler/WEB-INF/lib/kyee_nextframework_core-1.0.70.jar!/config/kyee-include-all.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Only one AsyncAnnotationBeanPostProcessor may exist within the context.
Offending resource: class path resource [config/core/scheduler.xml]

调查发现把项目部署在eclipse中时,lib目录下的jar包是正常的;部署到idea中以后,tomcat目录下webapps,进入到项目目录中,发现lib目录下有两个核心包,一个老版本,一个新版本。

于是到idea中查看了target目录下,是有两个核心包的,核心包被加载了两次,当然冲突了。下图是target目录:

IntelliJ IDEA 部署web项目时target目录下jar包冲突问题_第1张图片
image.png

所以就手动删除了老版本的核心包,重启以后项目就跑起来了。

IntelliJ IDEA 部署web项目时target目录下jar包冲突问题_第2张图片
image.png

冲突的jar包会显示成这样,一个是灰色的表示正常,另一个是黑色的应该的没什么用,但是却被错误的引入了进来,导致了项目无法启动,所以要将黑色的包删掉。

后记:
刚开始看日志报错一直以为是配置错误,还在jar包里看配置文件看是否哪里重复了,最后还是耐心看日志,发现在报错前已经加载了一遍配置文件,而且日志上写的很清楚,第一次加载的是老版本核心包的配置文件,然后加载新版本的配置文件就报错了。
所以排查问题时不能只看报错的那一行,要联系上下文,前后都得看一看。

你可能感兴趣的:(IntelliJ IDEA 部署web项目时target目录下jar包冲突问题)