Skip to content
Advertisement

An attempt was made to call a method that does not exist. STS

When i run the STS(SpringBoot) application i get the below error:

JavaScript

The following method did not exist:

JavaScript

The method’s class, javax.servlet.ServletContext, is available from the following locations:

JavaScript

It was loaded from the following location:

JavaScript

The suggestion in the ide is: Action:

Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext

I guess there is something wrong with my pom.xml the code is as below:

JavaScript

The main dependencies causing the error are:

JavaScript

I get the error only after adding the above dependencies, the need to add the dependencies is the below class:

JavaScript

Please help me resolve this issue. Thanks in advance

Advertisement

Answer

getVirtualServerName() was added in Servlet 3.1, but you included servlet-api-2.5.jar is your application.

Options:

  • Change your dependencies to include servlet-api-3.1.jar (or later)

  • Remove the servlet-api-2.5.jar dependency, since the correct version is included in the Embedded Tomcat file (tomcat-embed-core-9.0.33.jar).

Actually, you should never ship servlet-api.jar with your application, since it will be provided by the Servlet Container. Seems you’re missing <scope>provided</scope> in your dependency tag for the servlet-api file.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement