Spring MVC - Using @RequestMapping without path on class level

On class level @RequestMapping or @RequestMapping("") will map to only root url "/".


public class MyController {

  public String handler() {
      return "response from handler()";

Running example

To try examples, run embedded tomcat (configured in pom.xml of example project below):

mvn tomcat7:run-war


Check out this example as well when @RequestMapping without path is used on method level.

Example Project

Dependencies and Technologies Used:

  • spring-webmvc 5.0.4.RELEASE: Spring Web MVC.
  • javax.servlet-api 3.0.1 Java Servlet API
  • JDK 1.8
  • Maven 3.3.9

class-empty-handler-mapping Select All Download
  • class-empty-handler-mapping
    • src
      • main
        • java
          • com
            • logicbig
              • example

    See Also