The injection of the HttpServletRequest or HttpServletResponse into a @RequestMapping method in a @RestController class results in exceptions (at least in the @SpringBootTest annotation-enabled test):
@RequestMapping(value = '/doc/{collection}/{id}/{attr}/', method = RequestMethod.POST)
void updateAttr(
@PathVariable(value = 'collection', required = true) String collection,
@PathVariable(value = 'id', required = true) String uuid,
@PathVariable(value = 'attr', required = true) String attr,
@RequestParam(value = 'async', required = false) Boolean async = false,
@RequestParamJSON(value = 'detail', required = false) Detail customDetailJSON,
HttpServletRequest request
) {
error:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'apiController' method
public void ControllerClass.updateAttr(java.lang.String,java.lang.String,java.lang.String,java.lang.Boolean,cassdoc.Detail,javax.servlet.http.HttpServletRequest)
to {[/doc/{collection}/{id}/{attr}/],methods=[POST]}: There is already 'controllerClass' bean method
public void ControllerClass.updateAttr(java.lang.String,java.lang.String,java.lang.String,cassdoc.Detail,javax.servlet.http.HttpServletRequest) mapped.
Is this a bug in spring? Am I doing it wrong? I have almost-definitively tracked it down to the HttpServletRequest injection, not the @RequestParamJSON (a custom annotation that autodeserializes http params that are json) by process of elimination and noticing that other methods without the HttpRequest or HttpResponse injected into the method params work as expected.
Edit: versions:
compile group: 'org.springframework', name: 'spring-web', version: '4.3.8.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version: '1.5.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '1.5.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.5.3.RELEASE'
Oh, and I don't think it matters, but I am using groovy not java.