Share a common parent path when implementing Spring controllers Share a common parent path when implementing Spring controllers spring spring

Share a common parent path when implementing Spring controllers


Hmmm. You can try this, it is what works for me:

@RequestMapping("/abstract")public abstract class AbstractController {}@Controllerpublic class ExtendedAbstractController extends AbstractController {   @RequestMapping("/another")   public String anotherTest() {       return "another";   }}

Note, your base class must have no @Controller annotation and must be abstract.

If you try to do extend not abstract class annotated as controller and that has @RequestMappings you get errors on step where RequestMappingHandlerMapping initializing.


You can achieve it with:

  1. create sub-context configuration for controllers with same path prefix
  2. create sub-context with own DispatcherServlet mapped to certain path

Look at this answer. It's similar problem, but for @RestControllers.