Getting NoSuchMethodError:javax.servlet.ServletContext.getVirtualServerName()

前端 未结 9 1842
忘掉有多难
忘掉有多难 2020-11-28 13:03

I am facing an issue during deployment of a service in Tomcat 8. Getting following error :

Caused by: java.lang.NoSuchMethodError: javax.servlet.Ser

9条回答
  •  粉色の甜心
    2020-11-28 14:02

    The method getVirtualServerName has been added in ServletContext in Servlet 3.1. See the java doc's method getVirtualServerName.

    This problem has 3 primary causes:

    1. Your servlet version is older than 3.1.

    2. Some other jar has the servlet with a version older than 3.1.

    3. Your tomcat version is older than 8

    to solve it, you can try the below way.

    I. Check your pom.xml for the code below.

      
           javax.servlet
           javax.servlet-api
           3.1.0
        
    

    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-api jar. for example, the org.apache.santuario has refer to the javax.servlet-api jar. the pom.xml:

      
        org.apache.santuario  
        xmlsec  
        1.4.3   
     
    

    but when you look at the maven dependencies, it refer to the javax.servlet-api jar whose version is 2.3 older than 3.1.

    so you should exclude the 2.3 version. pom.xml:

      
      
        org.apache.santuario  
        xmlsec  
        1.4.3  
          
              
                javax.servlet  
                servlet-api  
              
          
      
    
      
      
        javax.servlet  
        javax.servlet-api  
        3.1.0  
     
    

    III. spring boot run the default tomcat 7. so define your tomcat version 8 instead of tomcat 7. so add the code your pom.xml:

       
            UTF-8
            UTF-8
            1.8
            8.5.5
        
    

提交回复
热议问题