NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang

阅读更多

 

 

springboot 启动报错 ,缺少  public abstract String getVirtualServerName(); 该方法

换用 引入高版本servlet-api,包含getVirtualServerName()方法 3.1.0 含getVirtualServerName


 

 

17:39:20.040 - A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost [localhost].StandardContext[]]
        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:911)
        at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:890)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1403)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:158)
        ... 6 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [Pipeline[StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:158)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5088)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
        ... 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:158)
        at org.apache.catalina.core.StandardPipeline.startInternal(StandardPipeline.java:170)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
        ... 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:1085)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
        ... 10 common frames omitted
17:39:20.041 - A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost]]
        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:911)
        at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:791)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
        at org.apache.catalina.startup.Tomcat.start(Tomcat.java:356)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:97)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.(TomcatEmbeddedServletContainer.java:83)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer

(TomcatEmbeddedServletContainerFactory.java:530)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer

(TomcatEmbeddedServletContainerFactory.java:176)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:535)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174)
        at com.hpe.ebtce.services.open.Application.main(Application.java:40)
        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:497)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:158)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1403)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919)
        at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:890)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
        ... 6 common frames omitted

 

 

 

servlet-api.jar 是否含有 java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()
 
 

 

引入高版本servlet-api,包含getVirtualServerName()方法 3.1.0 含

 

   
    javax.servlet  
    javax.servlet-api  
    3.1.0  

 

 

切换 tomcat 版本 选择非默认版本 8.5.23

 

 


		UTF-8
		UTF-8
		1.8
 		8.5.23  
		1.7.9
		1.0.1
		
	

 

 

 

注释 provided 如果javax.servlet-api 不存在java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName() Ljava.lang.String
public abstract String getVirtualServerName();

 


		
			javax.servlet
			javax.servlet-api
			 3.1.0 
			
		
		
			javax.servlet.jsp
			jsp-api
			2.1 
			
		

 

 maven compile provided 区别

 

对于scope=compile的情况(默认scope),也就是说这个项目在编译,测试,运行阶段都需要这个artifact对应的jar包在classpath中。
而对于scope=provided的情况,则可以认为这个provided是目标容器已经provide这个artifact。换句话说,它只影响到编译,测试阶段。在编译测试阶段,我们需要这个artifact对应的jar包在classpath中,而在运行阶段,假定目标的容器(比如我们这里的tomcat容器)已经提供了这个jar包,所以无需我们这个artifact对应的jar包了。

 

 

 

 

 

 

 

 

 

捐助开发者 

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(支持支付宝和微信 以及扣扣群),没钱捧个人场,谢谢各位。

 

个人主页:http://knight-black-bob.iteye.com/


NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang_第1张图片NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang_第2张图片NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang_第3张图片
 
 
 谢谢您的赞助,我会做的更好!

你可能感兴趣的:(java,springboot,exception,maven)