spring-data-rest

Spring Data Rest - Caching

≯℡__Kan透↙ 提交于 2019-11-30 13:31:08
问题 How to enable caching with Spring Data Rest? The reasoning behind is that repository listing and search methods won't change once the application is up. Also if the data behind the rest API is changed only through rest API it does makes a case to enable caching data too. I believe some level is caching happens in REST API framework and it would be ideal if the caching happens at the final response stage i.e., json response (to avoid the overhead of marshalling objects to json) Thoughts

How do I apply a projection to a Spring Data REST query method resource?

夙愿已清 提交于 2019-11-30 13:27:54
I'm using Spring Data REST 2.1.4.RELEASE. I created an entity Booking , its REST repository (extending CrudRepository ) named BookingRepository and a projection BookingDetails (annotated with @Projection(name="details", types = Booking.class) ) for returning some of its linked entities exploded, such as Resource , Activity , Applicant etc. The client gets all bookings with .../rest/bookings and the JSON response includes links for the linked entities. If it adds ?projection=details then the linked entities are exploded and returned. And this is great. Now I add this custom method to the

Modify @OneToMany entity in Spring Data Rest without its repository

浪子不回头ぞ 提交于 2019-11-30 12:14:33
问题 In my project I use object of type A which has OneToMany relation (orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.EAGER) to objects of type B . I need SpringDataRest (SDR) to store complete full A object with its B objects (children) using single one POST request. I tried several combinations in SDR, the only one which worked for me, was to create @RepositoryRestResource for object A and to create @RepositoryRestResource also for object B , but mark this ( B ) as exported

How to add custom methods to Spring Data Rest JPA implementation and leverage HATEOS support?

孤街醉人 提交于 2019-11-30 12:10:44
问题 I have a Spring Data Rest Repository controller that utilizes JPA for the query implementation, and I need to add some custom query methods that cannot be done using the standard queryByExample method that JPA supports. I have created an Impl class that has the necessary method, but I cannot get it to be recognized. I saw that I can utilize a standard Spring MVC Controller, but I want to have a unified API, and basically all I really want is to implement my own custom /search methods. Even

Difference between @RestController and @RepositoryRestController

拥有回忆 提交于 2019-11-30 11:34:27
What is the typical use case code that shows the difference between those two annotations - meaning the @RestController and the @RepositoryRestController - ? According to the annotation the RepositoryRestController is a way to provide custom controllers that still take advantage of spring data rest functionality http://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.overriding-sdr-response-handlers Sometimes you may want to write a custom handler for a specific resource. To take advantage of Spring Data REST’s settings, message converters, exception handling, and

Make collection propertie render as relation instead of property in json HAL representaion

强颜欢笑 提交于 2019-11-30 09:55:47
问题 I got hal formatted response as this: { "name": "Publisher A", "bookPublishers": [ { "publishedDate": "2019-07-12T08:19:04.583+0000", "_links": { "publisher": { "href": "http://localhost:8080/api/publishers/1" }, "book": { "href": "http://localhost:8080/api/books/2" } } }, { "publishedDate": "2019-07-12T08:19:04.564+0000", "_links": { "publisher": { "href": "http://localhost:8080/api/publishers/1" }, "book": { "href": "http://localhost:8080/api/books/1" } } } ], "_links": { "self": { "href":

Spring Boot (JAR) with multiple dispatcher servlets for different REST APIs with Spring Data REST

懵懂的女人 提交于 2019-11-30 09:42:20
I have a project that uses Spring Boot to generate an executable JAR that exposes a REST API with Spring Data REST. It is also integrated with Spring Security OAuth. That works fine. My problem is the following, I want to have different modules for the REST API that I want to enable only if the correspondent JAR with the JPA repositories is in the classpath (it has been defined as a dependency). The thing is I want them to be independent from each other. I want to be able to serve them under different dispatcher servlets with different mappings so I can specify different baseUri for each one

Spring Data REST: projection representation of single resource

荒凉一梦 提交于 2019-11-30 09:35:58
问题 I have a simple UserRepository which exposed using Spring Data REST . Here is the User entity class: @Document(collection = User.COLLECTION_NAME) @Setter @Getter public class User extends Entity { public static final String COLLECTION_NAME = "users"; private String name; private String email; private String password; private Set<UserRole> roles = new HashSet<>(0); } I've created a UserProjection class which looks the following way: @JsonInclude(JsonInclude.Include.NON_NULL) @Projection(types

Spring boot starter data rest, @Notnull constraint not working

為{幸葍}努か 提交于 2019-11-30 08:48:43
问题 I am trying to add @NotNull constraint into my Person object but I still can @POST a new Person with a null email. I am using Spring boot rest with MongoDB. Entity class: import javax.validation.constraints.NotNull; public class Person { @Id private String id; private String username; private String password; @NotNull // <-- Not working private String email; // getters & setters } Repository class: @RepositoryRestResource(collectionResourceRel = "people", path = "people") public interface

Spring Data REST - POST new entity with relationships

China☆狼群 提交于 2019-11-30 08:36:30
Relates to: Spring Data Rest version 2.0.2 I'm trying to POST an entity (Address) with a @ManyToOne (instead of @OneToOne as in example) relationship to Person as explained in: Embedded Entity references in complex object graphs but I get a Jackson Error: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: (was java.lang.NullPointerException) (through reference chain: Address["person"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: Address["person"]) at org