Skip to content

Support JSR 303 @Valid on @PathVariable [SPR-9840] #14473

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions