题主进行原有项目接口迁移新项目的时候遇到了如下问题:
运行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真的贼好用!!!大爱~~笔芯~~)