I have a ImportAction
class which serves as a parent class for several type-specific import controllers, such as ImportClientsAction
and ImportServicesAction
.
ImportAction
is a Spring MVC annotated @Controller
class and has @RequestMapping
-annotated methods to pull up a menu of import options and enter each of the type-specific import controllers.
Each child class, e.g. ImportClientsAction
is also annotated @Controller
and has type-specific @RequestMapping
s for their type's specific import process.
None of the @RequestMapping
s in any of the child classes should ever collide with the parent or with each other; each has a different path/value and different params.
From what I've come across in questions like this one and this one, it sounds like Spring counts each child class as having a duplicate of the parent class's @RequestMapping
-annotated methods, even if the child class does not override the parent's methods.
Is there a way to have an @Controller
-annotated parent class with @RequestMapping
s, and have @Controller
-annotated child classes, without Spring seeing the child classes as duplicating the parent's @RequestMapping
-annotated methods?
Bonus question, why can't Spring recognize a @RequestMapping
"duplicate" on a child class and just ignore all but the parent's version? Has this simply not been implemented, or is there a fundamental problem in Java that makes this impossible?
EDIT: Example code
Parent class example:
@Controller
public class ImportAction {
@RequestMapping(value = "/import", params = "m=importMenu", method = RequestMethod.GET)
public String importMenu(HttpServletRequest request) throws Exception {
return TilesConstants.IMPORT_MENU;
}
@RequestMapping(value = "/import", params = "m=importClients", method = RequestMethod.GET)
public String importClients(@ModelAttribute("ImportUploadForm") ImportUploadForm theForm, HttpServletRequest request) throws Exception {
retrieveReturnPage(request);
theForm.setSomeBoolean(true);
return TilesConstants.IMPORT_CLIENTS_UPLOAD;
}
@RequestMapping(value = "/import", params = "m=importServices", method = RequestMethod.GET)
public String importServices(@ModelAttribute("ImportUploadForm") ImportUploadForm theForm, HttpServletRequest request) throws Exception {
retrieveReturnPage(request);
theForm.setSomeBoolean(false);
return TilesConstants.IMPORT_SERVICES_UPLOAD;
}
/* etc 7 more almost identical methods */
}
Child class example:
@Controller
public class ImportClientsAction extends ImportAction {
@RequestMapping(value = "/importClients", params = "m=uploadClients", method = RequestMethod.POST)
public String uploadClients(@ModelAttribute("ImportUploadForm") ImportUploadForm theForm, BindingResult errors, HttpServletRequest request) throws Exception {
if (!parseAndStoreUploadedFile(theForm, errors, request)) {
return TilesConstants.IMPORT_CLIENTS_UPLOAD;
}
return "redirect:/importClients?m=enterMapClientsUpload";
}
/* etc other "client" type-specific import methods */
}