How to fix Spring 404 error

There are a lot of reason can cause 404 error in Spring MVC.

The biggest problem here is there are no clues to tell what happend from the console log, Tomcat console won't print any diagnostic information.

Here is a fast way to check what may possibly wrong.

The first thing is to tell whether the controller actually get called. Put a println statement in your controller, when the controller gets called, it will print a message to the Catalina console.

 
        System.out.println("did this get called?");
 

Something like this

If there is no output, means the Spring container can not find the controller. Check the ComponentScan configuration, if you are manually input it, its actually quite easy to misspell the package path name when its long, and since its just a string, no compiler warning or error will be displayed

The best way is always using the Copy the Qualified Name feature in Eclipse to copy the package path.