spring-data-rest

Spring Data - Overriding default methods for some repositories

有些话、适合烂在心里 提交于 2020-01-31 05:25:06
问题 I am just staring with spring-data and spring-data-rest and I really want to take advantage of what these tools have to offer. For the most case the base functionality is perfect for my use case however there are some cases where I need to customize the underlying functionality quite a bit, and selectively assign some repositories to inherit the customized functionality I am after. To explain the problem a bit better, in spring-data there are 2 possible interfaces which you can inherit

How do I set up unit tests for RepositoryRestController in Spring?

守給你的承諾、 提交于 2020-01-25 06:43:26
问题 I have the following configuration for my unit test for a RepositoryRestController (the MyController class): @RunWith(SpringRunner.class) @WebMvcTest public class MyTest { @Configuration @EnableSpringDataWebSupport static class TestConfiguration { @Bean MyController myController() { //controller construction } } } I can't find any documents online expounding on what sort of config I need to setup to get the tests running correctly. I only stumbled upon EnableSpringDataWebSupport when I was

Spring Boot and JPA Repository — how to filter a GET by ID

落花浮王杯 提交于 2020-01-24 19:59:04
问题 I'm rewriting an application, this time using a RESTful interface from Spring. I'm presuming that server-side authorization is best. That is: Supppose user 1 works this REST repository. He/she accesses mysite.com/heroes/1 and gets the (id = 1) hero from the hero table. User 2 doesn't have rights to see the (id = 1) hero, but could craft a cURL statement to try anyway. I claim the server should prevent user 2 from accessing the (id = 1) hero. I believe that the server can extract a JWT payload

Spring Data REST will export all its attributes (except the id).

若如初见. 提交于 2020-01-16 12:35:08
问题 I am currently in learning phase of Spring Data Rest. I developed one app in which I was able to succesfully expose the Rest Respoitory but with out the "ID". I searched over the internet to check if I am doing any thing wrong. However, one of the officially links (Official Doc) says, "Spring Data REST will export all its attributes (except the id). You can offer the consumer of your REST service an alternative by defining one or more projections." So if have more than ten entities. I have to

Spring Boot: Add Non-Repository REST Controller to HAL Links

為{幸葍}努か 提交于 2020-01-16 08:33:20
问题 The problem: I have a simple Spring Boot app, using Spring Data REST and HATEOAS, with a JPA Entity class which calls a MySql Function (not a table). The rest of my repos are displayed in a nice HAL set of hyperlinks, but this one function is not discoverable (not in the list). How do I add it into the HAL links? @Entity(name = "GetOptionsForStyle") @Table(name = "get_options_for_style") @NamedNativeQueries({ @NamedNativeQuery(name = "getOptionsByStyleId", query = "SELECT `f1`.`get_options

$addToSet implementation for array update on PATCH request

╄→гoц情女王★ 提交于 2020-01-15 09:46:06
问题 Is there a way to tell MongoRepository to implement $addToSet when updating an array value during PATCH request? I am using Spring data rest with HATEOAS and Mongodb, and the current implementation replaces the old array with the new array, where the desired functionality is to perform a union of both arrays and have that array stored in the Mongodb document. While it should be possible to do that with custom implementation, Spring won't generate a rest url for the implementation and hence

Excerpt Projection and Custom Links from ResourceProcessor

馋奶兔 提交于 2020-01-14 14:26:07
问题 I am using spring-data-rest 2.4.1 to expose a entity as a rest resource. I also implemented a ResourceProcessor to add a custom link to the resource @Component public class MyEntityResourceProcessor implements ResourceProcessor<Resource<MyEntity>> { @Override public Resource<MyEntity> process(Resource<MyEntity> resource) { resource.add(linkTo(methodOn(CustomController.class).getFeatures(resource.getContent().getId())).withRel("customRel")); return resource; } } This works fine for the single

How to add custom links to non repository rest controller in spring data rest hal?

本秂侑毒 提交于 2020-01-13 22:40:02
问题 I would like to add custom rest controller to be added to the json/hal response of the entry point, together with all the respositories that are added by spring. I'm struggling with this by two problems: How can I add my custom controller so it appears on the entry point together with the links to my repository? How can I decorate with a link to my custom controller on a representation of an entity produced by the repository so I can link to my custom controller? I have struggled for a while

Spring Data Rest - Parameters with default values

此生再无相见时 提交于 2020-01-13 09:59:10
问题 I have created the following @RepositoryRestResource query where I want to create a dynamic query for my rest api. So basically I would want to do something like: myHost/myApp/data/search/all?name=me&age=20&address=myhome&etc=etc So I have created the query below: @Query("Select t from Data t " + "where " + "t.name like :name AND " + "t.age = :age AND " + "t.address = :address AND " + "t.etc= :etc" @RestResource(path = "all", rel = "all") Page findByAll(@Param("name") String name, @Param("age

Swagger not detecting Spring Data Rest APIs with Spring Boot

独自空忆成欢 提交于 2020-01-12 01:37:07
问题 I setup a Spring Boot project including Spring Data Rest and Swagger: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-rest</artifactId> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.4.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.4.0</version> </dependency> This is my Swagger configuration: