IntelliJ with Spring boot: cannot find symbol GetMapping and RequestParam

Viewed 4579

I'm following the Spring tutorial on the JetBrains website and when I try to build and run after adding the sayHello() method, it tells me it cannot find symbol RequestParam and GetMapping:

@GetMapping("/hello")
    public String sayHello(@RequestParam(value = "myName", defaultValue = "World") String name) {
        return String.format("Hello %s!", name);
    }

Error message:

Error:(14, 29) java: cannot find symbol
  symbol:   class RequestParam
  location: class com.example.demo.DemoApplication
Error:(13, 6) java: cannot find symbol
  symbol:   class GetMapping
  location: class com.example.demo.DemoApplication
2 Answers

I forgot to import the annotations. Silly me

Have you included spring-starter-web dependency?? If yes try to import those dependencies sometimes it is not imported by default you need to build project or click on import dependencies in IntelliJ.

Related