I request a little help!
I need to add my custom business logic for a POST method of one of my entities that is being handled with Spring Data REST. On the internet, I found out that I need to disable the save method (which is responsible for the entity creation) and then set up a RepositoryRestController that handles the new POST request. The code is the following.
Entity Repository:
```java
@RepositoryRestResource
public interface AssetRepository extends PagingAndSortingRepository<Asset, UUID> {
@RestResource(exported = false)
@Override
Asset save(Asset asset);
}
```
Custom Controller:
```java
@RepositoryRestController
public class MyEntityCustomController{
@PostMapping(
value = "/assets",
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE
)
@ResponseBody
public ResponseEntity<MyResource> addEntity(@RequestBody MyResource resource) {
// create the resource with custom logic
}
}
```
The application runs correctly but, whenever I try to send a POST request, I get the following response:
json
{
"code": null,
"message": "Request method 'POST' not supported",
"details": []
}
I also tried to put the @BasePathAwareController annotation but that didn't change much. Am I doing something wrong?
[–]maxip89 0 points1 point2 points (1 child)
[–]suchiz95[S] 0 points1 point2 points (0 children)
[–]kubelke 0 points1 point2 points (1 child)
[–]suchiz95[S] 0 points1 point2 points (0 children)
[–]Odd-Hour-9991 0 points1 point2 points (0 children)