Given the following working repository in our application:
public interface PersonRepository extends PagingAndSortingRepository<Person, Integer> {
}
The Repository is exposed via spring-data-rest with URI "/api/persons" and works as expected.
We now want to override the post-method of the repository in a method of a RestController:
@RestController
@RequestMapping("/persons")
public class PersonController {
@RequestMapping(value = "/**", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> savePerson(@RequestBody Person person) {
//do something fancy
return "it works";
}
If we post data to "/api/persons" the method of the PersonController is called but none of the methods of the PersonRepository (e.g. GET) can be accessed via rest. We constantly get an 405 error and the following exception:
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported
After some playing around we found out that everything works as expected (methods of repository and controller can be called) if we change the value-property of the @RequestMapping annotation from
value="/**"
to
value="/save"
After reading this question and the linked documenation it should also work if the value-property is "/**"
Finally, after upgrading to new versions of spring/spring-data/spring-data-rest everything works as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With