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 @RequestMapping
s you get errors on step where RequestMappingHandlerMapping
initializing.
You can achieve it with:
- create sub-context configuration for controllers with same path prefix
- create sub-context with own
DispatcherServlet
mapped to certain path
Look at this answer. It's similar problem, but for @RestControllers
.