I faced the same problem, and there are a lot of solutions given in the answer, trying all these solutions took me quite some time, so here I would like to propose a methodical approach if you get this error.
Check for the following things, create/update if something is missing
If everything is fine, you can try following solutions in given order
Recompile the file/module
If that didn't fix the issue, try refreshing maven dependency and building the project using Maven -> Reimport
and Build -> Rebuild Project
Try mvn clean install -DskipTests
Try invalidating the IntelliJ cache and restarting the IDE, using File > Invalidate caches/ restart
Delete the .idea folder and reimport the project
Credit and Thanks to everyone who answered this question, you can refer to their answers for more description regarding each point.