Closed
Description
Neil Laurance opened SPR-9840 and commented
Similar to #11041.
I have a controller with the following:
@Controller
public class BookController {
@RequestMapping("/books/{isbn}")
public @ResponseBody Book getBook(@Valid @PathVariable("isbn") Isbn isbn) {
return bookService.getBook(isbn);
}
// thrown when validation fails
@ExceptionHandler(BindException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public void bindException() {}
}
Where I have registered a custom converter:
<mvc:annotation-driven conversion-service="conversionService" />
<bean id="conversionService" class="...">
<property name="converters">
<set>
<bean class="common.domain.StringIsbnConverter" />
</set>
</property>
</bean>
When I run this, my validation code annotation is ignored.
However, if I remove @PathVariable
, then the code still works, although my IDE warns that 'URI template variable "isbn" is not defined'.
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#validation-mvc-triggering suggests this should work.
Affects: 3.1.1
Issue Links:
- Support for javax.validation annotations on @PathVariable, @RequestHeader, @RequestParam [SPR-6380] #11041 Support for javax.validation annotations on
@PathVariable
,@RequestHeader
,@RequestParam