spring-data-rest

Two repos for the same entity, one exported and one not

孤者浪人 提交于 2019-12-22 07:47:48
问题 Using Sring Data JPA, Spring Data REST 2.4.2, Spring Security and Spring Boot 1.3.1. I have an Account entity that I want to expose over REST for admin purposes: @PreAuthorize("hasRole('ROLE_ADMIN')") //exclusive admin access public interface AccountRepository extends JpaRepository<Account, Long> {} This works as expected and I can access the REST interface with a proper admin role. Another requirement I have is to allow non-admin users to register and authenticate over HTTP. For that I've

Spring Data Rest - Proxy path not including link path

两盒软妹~` 提交于 2019-12-22 06:59:15
问题 I'm proxying a Spring REST backend like so: Backend: http://backend:8080 Proxied localhost: localhost:3000/api/backend -> http://backend:8080 If I browse locally to a proxied endpoint, it will proxy the request, the links, however, do not include the proxy path, i.e. GET localhost:3000/api/backend/people "href": "http://localhost:3000/people" I would expect this to be: "href": "http://localhost:3000/api/backend/people" There any way to fix this? Thanks! 回答1: You should have a look at the x

Spring data REST findBy nested entity

☆樱花仙子☆ 提交于 2019-12-22 06:23:43
问题 I have a Spring Boot project using Spring-data-rest for generating my REST interface and I am trying to allow pagination for nested resources. I followed this workaround and got stuck with implementing the findBy query. I have the following Device entity: @Entity @Table(name = "devices") public class Device extends ResourceSupport { ... @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; } I need to query it using userId: @RequestMapping(path = "/users/{id}

Spring data REST findBy nested entity

混江龙づ霸主 提交于 2019-12-22 06:23:15
问题 I have a Spring Boot project using Spring-data-rest for generating my REST interface and I am trying to allow pagination for nested resources. I followed this workaround and got stuck with implementing the findBy query. I have the following Device entity: @Entity @Table(name = "devices") public class Device extends ResourceSupport { ... @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; } I need to query it using userId: @RequestMapping(path = "/users/{id}

Fetching & Updating lazy-loaded many-many fields in Spring Data REST

杀马特。学长 韩版系。学妹 提交于 2019-12-22 05:20:22
问题 How do I correctly expose lazy-loaded many-many fields so that users can GET / PATCH / POST / DELETE many-many entity relationships in Spring Data REST? For example, given a Student entity and Teacher entity bound by a many to many relationship, with the following POJOs: @Entity public class Teacher { // owner of bidirectional relationship @Id private int id; private String name; @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "teacher_student", joinColumns = @JoinColumn(name = "teacher

Spring Data REST Events Not working [duplicate]

痞子三分冷 提交于 2019-12-21 23:19:51
问题 This question already has answers here : Spring Data Rest: RepositoryEventHandler methods not invoked (2 answers) Closed 4 years ago . I have tried to configure spring data rest event as per follows.All classes are in package org.springbootjpa Events: http://docs.spring.io/spring-data/rest/docs/current/reference/html/#events Following is my code @SpringBootApplication public class DemoApplication { public static void main(String[] args) { ApplicationContext context = SpringApplication.run(

Post an entity with Spring Data REST which has relations

≯℡__Kan透↙ 提交于 2019-12-21 17:23:29
问题 I'm using Spring Data Rest. I have a problem trying to POST an object with association(e.g. address is a field in my entity that is mapped as many to one). The question is, what format should we use to connect our new entity with its relations. I saw several answers and tried all options that I found. Unfortunately, all of them don't work for me. The following error happens: Caused by: org.h2.jdbc.JdbcSQLException: NULL not allowed for column "ADDRESS_ID"; SQL statement: JSON that I tried: {

Spring Data Rest - How to receive Headers in @RepositoryEventHandler

谁都会走 提交于 2019-12-21 05:25:09
问题 I'm using the latest Spring Data Rest and I'm handling the event " before create ". The requirement I have is to capture also the HTTP Headers submitted to the POST endpoint for the model " Client ". However, the interface for the RepositoryEventHandler does not expose that. @Component @RepositoryEventHandler public class ClientEventHandler { @Autowired private ClientService clientService; @HandleBeforeCreate public void handleClientSave(Client client) { ... ... } } How can we handle events

Spring Data Rest: how to register a custom conversionService with custom Converter<Entity, Resource>?

余生长醉 提交于 2019-12-21 05:24:23
问题 There is something that is not enough clear in this part of Spring Data Rest documentation: The Spring Data REST exporter executes any discovered ResourceProcessor`s before it creates the output representation. For what I have noticed, it's true: ResourceProcessor are invoked during the handling of the request, after the completion of RepositoryEntityController respective method. It does this by registering a Converter<Entity, Resource> instance with an internal ConversionService. I don't

How to expose a complete tree structure with Spring Data REST and HATEOAS?

坚强是说给别人听的谎言 提交于 2019-12-21 02:43:14
问题 I have a JPA tree structure @Entity public class Document { @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; private String text; @ManyToOne @JoinColumn(name = "parent") Document parent; @OneToMany(mappedBy = "parent", fetch = FetchType.EAGER) Set<Document> children; (getters and setters) } and a projection @Projection(name = "all", types = Document.class) public interface AllDocumentsProjection { int getId(); String getText(); Set<Document> getChildren(); } When I make a