0

I am learning Spring Boot and I don't have any prior experience regarding this. I am facing two errors that I tried to solve for hours still I can't get through them.

Here is the exact Ss of the errors

The first error is "Cannot resolve symbol 'annotation'" The second one is "Cannot resolve symbol 'WebServlet'"

This is my first day with spring boot. I want to know the reason why in the first error, ie in line 3 I am getting an error with just annotations while the rest words from the statements seem to be dead and why I am getting an error with WebServlet in line 8 but not in line 3. Also please help me solve the issue.

DrDoggo
  • 149
  • 10
  • 1
    Does this answer your question? [Servlet 5.0 JAR throws compile error on javax.servlet.\* but Servlet 4.0 JAR does not](https://stackoverflow.com/questions/64387472/servlet-5-0-jar-throws-compile-error-on-javax-servlet-but-servlet-4-0-jar-does) – Piotr P. Karwasz Mar 26 '21 at 21:25
  • Since you are compiling against Tomcat 10, all your imports should start with `jakarta`. – Piotr P. Karwasz Mar 26 '21 at 21:28

1 Answers1

1

why I am getting an error with WebServlet in line 8 but not in line 3

You get that error also in line 3 but in that line the package name annotation is red because it can't find that package. If it can't find the package for sure it can not find the class in that package that it searches for. It gives you a red symbol to understand where the problem starts from.

At line 8 you get WebServlet error because as it is obvious it could not import that class from previous step (line 3)

As Piotr P. Karwasz already commented, for tomcat 10 the package that contains the class WebServlet has changed.

You must change

import javax.servlet.annotation.WebServlet

to import jakarta.servlet.annotation.WebServlet

Panagiotis Bougioukos
  • 15,955
  • 2
  • 30
  • 47