`
knight_black_bob
  • 浏览: 853220 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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.<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/



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

0
0
分享到:
评论

相关推荐

    java.lang.NoSuchMethodError: javax/servlet/jsp/PageContext.getELContext()Ljavax/

    NULL 博文链接:https://albert0707.iteye.com/blog/562969

    maven3.6.3资源包

    1) Error injecting constructor, java.lang.NoSuchMethodError: org.apache.maven.model.validation.DefaultModelValidator: method 'void ()' not found at org.jetbrains.idea.maven.server.embedder....

    java.lang.NoSuchMethodError异常处理要点.doc

    在Java编程中,`java.lang.NoSuchMethodError`异常是一个运行时异常,通常发生在程序试图执行一个不存在的方法时。这个异常的出现通常意味着编译时和运行时的类版本不匹配,或者是在编译期间存在而运行时不存在的...

    解决启动Azkaban报错问题:java.lang.NoSuchMethodError: com.google.common.collect.ImmutableMap.toImmutableMap

    在Java编程中,`NoSuchMethodError` 是一个常见的运行时异常,它表示在类加载时找到了该类,但在该类中却找不到特定方法的定义。这个问题通常发生在不同版本的库之间存在不兼容的情况,即在编译时使用的库版本包含了...

    jedis-3.3.0.jar

    java.lang.NoSuchMethodError: redis.clients.jedis.ScanResult.getStringCursor()Ljava/lang/String; at org.crazycake.shiro.WorkAloneRedisManager.keys(WorkAloneRedisManager.java:149) at org.crazycake....

    解决 java.lang.NoSuchMethodError的错误

    解决 java.lang.NoSuchMethodError 的错误 Java.lang.NoSuchMethodError 错误是一种常见的 Java 异常,它发生在 Java 虚拟机 (JVM) 无法找到某个类的特定方法时。这种错误可能是由于项目依赖比较复杂、Java 运行...

    xwork-core-2.3.37.jar

    用于解决struts2升级至2.3.37时 出现java.lang.NoSuchMethodError: com.opensymphony.xwork2.ActionContext.put(Ljava/lang/异常时,更换的xwork-core-2.3.37.jar

    java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingExcepti

    jackson-annotations-2.10.2.jar jackson-core-2.10.2.jar jackson-databind-2.10.2.jar NoClassDefFoundError解决

    jboss-logging.jar,jboss-common.jar

    java.lang.NoSuchMethodError: org.jboss.logging.Logger.getMessageLogger(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Object; 错误解决办法

    java.lang.NoSuchMethodError异常解决

    在Java编程中,`java.lang.NoSuchMethodError`异常是一个运行时异常,通常发生在尝试执行一个在编译时可用但在运行时不可用的方法时。这个异常表明某个已经加载的类定义了一个方法,但该方法的实际行为无法被找到。...

    jersey-core-1.9.jar

    解决java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map; 已经打包好的,放心使用,可反编译查看下

    hibernate3.2+cglib2.2架包

    在Java中,有时我们可能会遇到`java.lang.NoSuchMethodError`,这通常发生在运行时尝试执行一个在编译时存在但在运行时不存在的方法。对于这个问题,CGlib提供了解决方案。CGlib使用ASM库(一个Java字节码操纵和分析...

    Org.BouncyCastle.Utilities.Encoders 等命名空间所需库

    主要用于加解密,我是在使用解密SM4 时接触到的,在网上代码引用了Org.BouncyCastle.Utilities.Encoders,找不到库 自己在网上找了好久找到了,没有积分的可以去http://www.bouncycastle.org/csharp/ 下载

    slf4j-1.7.rar

    1.如果运行程序出现错误:“Exception in thread "main...3.错误:“Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.MDC.getCopyOfContextMap()Ljava/util/Map”,这是因为jar包版本冲突造成的。

    jstl1.1.jar和standard1.1.jar

    错误信息:java.lang.NoSuchMethodError: javax.servlet.JSP.PageContext.getELContext()LJAVAx/el/ELContext 分析:这个问题网上找了半天没看到解决方法,只好自己想办法。想起先前看到的一个知识点:tomcat 6 ...

    JSTL1.1(tomcat5使用)

    JSTL1.1包含两个部分standard.jar和jstl.jar 使用JSTL时tomcat5.5最好是使用jstl1.1。...使用jstl时如果出现java.lang.NoSuchMethodError: javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;

    Android 出现:java.lang.NoClassDefFoundError…错误解决办法

    在Android开发过程中,有时会遇到一个令人困惑的错误——`java.lang.NoClassDefFoundError`。这个错误通常意味着在运行时找不到某个类的定义,即使编译时该类是可用的。在本例中,问题出在一个特定的情景:在Android...

Global site tag (gtag.js) - Google Analytics