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

简介:     springboot 启动报错 ,缺少  public abstract String getVirtualServerName(); 该方法 换用 引入高版本servlet-api,包含getVirtualServerName()方法 3.

 

 

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.<init>(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 含

 

 <dependency>  
    <groupId>javax.servlet</groupId>  
    <artifactId>javax.servlet-api</artifactId>  
    <version>3.1.0</version>  
</dependency>

 

 

切换 tomcat 版本 选择非默认版本 <tomcat.version>8.5.23</tomcat.version>

 

 

<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
 		<tomcat.version>8.5.23</tomcat.version>  
		<org.slf4j-version>1.7.9</org.slf4j-version>
		<org.logback-version>1.0.1</org.logback-version>
		
	</properties>

 

 

 

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

 

<!-- servlet 3.0 start -->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			 <version>3.1.0</version> 
			<!--   <scope>provided</scope>   -->
		</dependency>
		<dependency>
			<groupId>javax.servlet.jsp</groupId>
			<artifactId>jsp-api</artifactId>
			<version>2.1</version> 
			<!--  <scope>provided</scope>   -->
		</dependency>
<!-- servlet 3.0 end -->

 

 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/



 
 
 谢谢您的赞助,我会做的更好!

目录
相关文章
|
人工智能 前端开发 Java
Java真过饱和了吗?现在学Java迟了?
Java真过饱和了吗?现在学Java迟了?
113 0
|
4月前
|
安全 Java API
Java中的Servlet编程详解
Java中的Servlet编程详解
|
6月前
|
XML 小程序 Java
Java Servlet
Java Servlet
46 0
Java Servlet
|
6月前
|
算法 Java 开发者
Java:求正整数分解为质因数Java
Java:求正整数分解为质因数Java
|
6月前
|
Java 程序员 C++
【Java】Java与C++:比较与对比
【Java】Java与C++:比较与对比
92 0
|
11月前
|
存储 Java PHP
【零基础学Java】—初识Java(一)
【零基础学Java】—初识Java(一)
|
缓存 前端开发 JavaScript
JAVA-JSP/Servlet 笔记(八)
JAVA-JSP/Servlet 笔记(八)
|
Java 关系型数据库 MySQL
JAVA 笔记-JSP/Servlet(七)
JAVA 笔记-JSP/Servlet(七)
|
Java 编译器
【JAVA】初识Java
一些IDEA 里面的快捷键 JAVA开发环境 操作IDEA的动作分解 以类(class)为基本单位进行组织 数据(data) 基本数据类型 变量 字面量
131 0
|
Java
Java常见的坑(二)
你猜上述程序输出的是什么? 是 ABC easy as 123 吗? 你执行了输出操作,你才发现输出的是 ABC easy as [C@6e8cf4c6 ,这么一串丑陋的数字是什么鬼? 实际上我们知道字符串与任何数值的相加都会变为字符串,上述事例也不例外, numbers输出其实实际上是调用了Object.toString()方法,让numbers转变为'[c' + '@' + 无符号的十六进制数。
85 0