idea中解决gradle依赖包冲突的问题

题主进行原有项目接口迁移新项目的时候遇到了如下问题:

运行gradle clean build是成功的

但是启动main函数就是不成功,在这里楼主用的是springboot的main函数启动方法

2018-06-06 16:04:43.060 [Tomcat-startStop-1] ERROR org.apache.catalina.core.ContainerBase:  A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]
	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.util.concurrent.FutureTask.get(FutureTask.java:192)
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:941)
	at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:872)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1421)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1411)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
	... 6 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [Pipeline[StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5125)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	... 6 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.authenticator.NonLoginAuthenticator[]]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
	at org.apache.catalina.core.StandardPipeline.startInternal(StandardPipeline.java:182)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	... 8 common frames omitted
Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
	at org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1186)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	... 10 common frames omitted



可以看到最终的问题是:

Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
	at org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1186)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	... 10 common frames omitted



找不到javax.servlet.ServletContext的getVirtualServerName()方法,而项目中应该调用的是Tomcat中的ServletContext.getVirtualServerName()方法,所以我们就要把javax.servlet.ServletContext的getVirtualServerName()方法从gradle配置文件中清除并重新引入依赖就可以了,那么我们如何找到对应的文件在配置文件中的什么哪个包呢?


idea中双击shift可以找到对应的依赖位置

可以看到这里引入的不正确的包是 external:servlet-api:2.4.pd

在右侧的gradle工具中,可以查看整体的依赖关系图

运行这个按钮,在运行结构中搜索external:servlet-api:2.4就可以从树状图看出对应的从属关系,然后在build.gradle中将对应依赖中移除这个模块就可以了,这里楼主就不演示搜索了,因为我已经把对应依赖移除了~~~~




然后找到引入的模块,在build.gradle文件中将其移除

compile(configuration: 'core', group: 'toolbox', name: 'web-tools', version: '2.0.+') {
        exclude(module: 'spring')
        exclude(module: 'commons-codec')
        exclude(module: 'slf4j')
        exclude(module: 'servlet-api')
    }



再用gradle工具刷新工程,重新导入包再重启项目就可以了~~~(在这里不得不再夸一下idea真的贼好用!!!大爱~~笔芯~~)





评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值