Spring Cloud (4) | NoSuchMethodError:javax.servlet.ServletContext.getVirtualServerName()
2017-11-27 12:05
423 查看
the method
this problem can have at least 3 causes:
your servlet version is older that 3.1.
other jar has the servlet older version than 3.1.
your tomcat version is older than 8
to solve it, you can try the below way.
I. to check your pom.xml whether there are the below code.
if your pom.xml has the above code, it would still has that problem. you can do the second way.
II. to check your other jar has refer to the
but when you look at the maven dependencies, it refer to the
so you should exclude the 2.3 version. pom.xml:
III. spring boot run the default tomcat 7. so define your tomcat version 8 instead of tomcat 7. To add the code your pom.xml:
原文链接:https://stackoverflow.com/questions/34950164/getting-nosuchmethoderrorjavax-servlet-servletcontext-getvirtualservername/47503564#47503564
更多系列文章推荐:
Spring Cloud (20) | Spring Cloud Bus 使用kafka消息总线、gitlab添加webhooks实现自动刷新配置
Spring Cloud (19) | Eureka Server 高可用服务注册中心
Spring Cloud (18) | 给Eureka Server加上安全验证
Spring Cloud (15) | Spring Boot、HikariCP、Mybatis和MySQL 配置HikariCP数据库连接池
Spring Cloud (14) | 微服务不能从git/github/gitlab中获取数据库信息 can’t load properties from git/github/gitlab
Spring Cloud (12) | Spring Cloud Zuul网关调用微服务,request请求参数是application/json
Spring Cloud (11) | healthcheck开启健康检查
Spring Cloud (10) | Eureka 各项参数详解
Spring Cloud (8) | 把Spring Boot项目改造成tomcat容器启动
Spring Cloud (7) | Mongodb 微服务
Spring Cloud (6) | spring cloud zuul 跨域问题No ‘Access-Control-Allow-Origin’ header
Spring Cloud (5) | 配置中心 Config Server 配置git or github or gitlab
Spring Cloud (3) | spring cloud bus 消息总线kafka应用
Spring Cloud (1) | java.net.UnknownHostException: eureka-server
getVirtualServerNamehas been added in ServletContext in Servlet 3.1. Find the java doc’s method getVirtualServerName
this problem can have at least 3 causes:
your servlet version is older that 3.1.
other jar has the servlet older version than 3.1.
your tomcat version is older than 8
to solve it, you can try the below way.
I. to check your pom.xml whether there are the below code.
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency>
if your pom.xml has the above code, it would still has that problem. you can do the second way.
II. to check your other jar has refer to the
javax.servlet-apijar. for example, the
org.apache.santuariohas refer to the
javax.servlet-apijar. the pom.xml:
<dependency> <groupId>org.apache.santuario</groupId> <artifactId>xmlsec</artifactId> <version>1.4.3</version> </dependency>
but when you look at the maven dependencies, it refer to the
javax.servlet-apijar whose version is 2.3 older than 3.1.
so you should exclude the 2.3 version. pom.xml:
<!-- exclude servlet-api 2.3 jar--> <dependency> <groupId>org.apache.santuario</groupId> <artifactId>xmlsec</artifactId> <version>1.4.3</version> <exclusions> <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> </exclusions> </dependency> <!-- servlet-api 3.1 version has getVirtualServerName() --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency>
III. spring boot run the default tomcat 7. so define your tomcat version 8 instead of tomcat 7. To add the code your pom.xml:
<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.5</tomcat.version> </properties>
原文链接:https://stackoverflow.com/questions/34950164/getting-nosuchmethoderrorjavax-servlet-servletcontext-getvirtualservername/47503564#47503564
更多系列文章推荐:
Spring Cloud (20) | Spring Cloud Bus 使用kafka消息总线、gitlab添加webhooks实现自动刷新配置
Spring Cloud (19) | Eureka Server 高可用服务注册中心
Spring Cloud (18) | 给Eureka Server加上安全验证
Spring Cloud (15) | Spring Boot、HikariCP、Mybatis和MySQL 配置HikariCP数据库连接池
Spring Cloud (14) | 微服务不能从git/github/gitlab中获取数据库信息 can’t load properties from git/github/gitlab
Spring Cloud (12) | Spring Cloud Zuul网关调用微服务,request请求参数是application/json
Spring Cloud (11) | healthcheck开启健康检查
Spring Cloud (10) | Eureka 各项参数详解
Spring Cloud (8) | 把Spring Boot项目改造成tomcat容器启动
Spring Cloud (7) | Mongodb 微服务
Spring Cloud (6) | spring cloud zuul 跨域问题No ‘Access-Control-Allow-Origin’ header
Spring Cloud (5) | 配置中心 Config Server 配置git or github or gitlab
Spring Cloud (3) | spring cloud bus 消息总线kafka应用
Spring Cloud (1) | java.net.UnknownHostException: eureka-server
相关文章推荐
- NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String
- NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String
- java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
- java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()
- spring-boot启动不了,报错 java.lang.NoClassDefFoundError: javax/servlet/ServletContext
- 启动spring-boot报错java.lang.NoClassDefFoundError: javax/servlet/ServletContext
- 【原】tomcat 7 启动报错:java.lang.NoSuchMethodError: javax.servlet.ServletContext.getSessionCookieConfig()Ljavax/servlet/SessionCookieConfig的解决
- previously initiated loading for a different type with name "javax/servlet/ServletContext"
- 【Spring Cloud】Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCon
- 【Spring Cloud】Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCon
- Caused by: java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getServletContext()Lja
- spring cloud java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
- java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()Ljava/lang/String;
- javax.servlet.ServletRequest 的getAttribute(String name)与getParmeter(String name)的区别
- 【Spring Cloud】Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCon
- 【Spring Cloud】Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCon
- Spring Cloud ZooKeeper集成Feign的坑2,服务调用了一次后第二次调用就变成了500,错误:Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.n
- request的相关方法在实际中的应用 getContextPath() getServerName():
- <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
- java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()Ljava/lang/String;