I hit this attempting to do similar so I thought I'd share my findings.
With using most defaults and your code, the search method will be mapped to /v1/books/:search
which is obviously not quite what you want. There are two places that I've found so far that get in the way of changing this. The first is the AntPathMatcher's combine method. This method will attempt to put a path separator (/) between segments. The second place is within the RequestMappingInfo's path parsing code. The former can be replaced easily. The latter not so much.
As the methods that tend to be problematic involve combining multiple @RequestMapping
annotations, what I've found to work is to simply side-step combinations. On my controller class, I have a @Controller
annotation and any defaults for @RequestMapping
, but not a path attribute. On each method, the full path is then added. This isn't great, but it does get collection-level special "methods" to function properly. In your example, this would look like:
@Controller
@RequestMapping
public class BooksController {
@GetMapping("/v1/books:search")
public Page<Book> search(@RequestParam String author) {
// Return books written by the author.
}