spring-data-rest

How to expose @EmbeddedId converters in Spring Data REST

随声附和 提交于 2019-11-27 02:00:06
问题 There are some Entities with composite Primary Keys and these entities when exposed are having incorrect Links having full qualified name of classes in URL inside _links Also clicking on links gives such errors - org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type java.lang.String to type com.core.connection.domains.UserFriendshipId I have XML configured Spring Repository with jpa:repositories enabled and Respository extending from

Enable HAL serialization in Spring Boot for custom controller method

浪尽此生 提交于 2019-11-27 01:30:21
I'm trying to build a RESTful API with Spring Boot using spring-boot-starter-data-rest. There are some entities: accounts, transactions, categories and users - just the usual stuff. When I retrieve the objects at http://localhost:8080/transactions via the API that has been generated by default, all is going well an I get a list with all transactions as JSON objects like that one: { "amount": -4.81, "date": "2014-06-17T21:18:00.000+0000", "description": "Pizza", "_links": { "self": { "href": "http://localhost:8080/transactions/5" }, "category": { "href": "http://localhost:8080/transactions/5

While using Spring Data Rest after migrating an app to Spring Boot, I have observed that entity properties with @Id are no longer marshalled to JSON

China☆狼群 提交于 2019-11-26 22:39:34
This question is related to this SO question ( Spring boot @ResponseBody doesn't serialize entity id ). I have observed that after migrating an app to Spring Boot and using the spring-boot-starter-data-rest dependency, my entity @Id fields are no longer marshalled in the resulting JSON. This is my request mapping and while debugging, I can see the data isn't being changed prior to returning it, so the @Id properties are being stripped later on. @RequestMapping(method = RequestMethod.GET, produces = {"application/json"}) public PagedResources<Receipt> receipts(Pageable pageable,

Spring Data Rest: Security based projection

徘徊边缘 提交于 2019-11-26 22:34:55
问题 I am using the current version of Spring Data Rest and Spring Data JPA and have following entity: public class User { @Id @GeneratedValue private Long id; private String name; private String password; private String email; ...getter/setter methods... } I am also using Spring Security . My User Repository: @RepositoryRestResource( collectionResourceRel = "user", path = "user", excerptProjection = UserSimpleProjection.class) public interface UserRepository extends PagingAndSortingRepository

How to customize Spring Data REST to use a multi-segment path for a repository resource?

谁说胖子不能爱 提交于 2019-11-26 22:01:26
问题 I'm developing a component based CRUD application using Spring Data JPA and Spring Data REST. I have several components. For example system component has the User model and the UserRepository . Components are differenciated by the package names. like com.example.app.<component_name> So to make my REST API look cleaner, I need to implement the API URL as below. host:8080/<component_name>/<model_collection_name> for example host:8080/system/users I did the following in my repository

How to configure Spring HATEOAS behind proxy?

孤街浪徒 提交于 2019-11-26 21:19:08
问题 I have Spring Data Rest with Hateoas as my backed. It is behind a proxy. Backend url: backend.com Proxy url: proxy.com When I query proxy url, e.g. http://proxy.com/items/1 , I get a response with href links with domain backend.com . I need the domain to be proxy.com . 回答1: As of Spring-Boot 2.1 / Spring 5.1, Spring shifts the responsibility of handling X-Forwarded-* from Spring HATEOAS to Spring MVC. https://jira.spring.io/browse/SPR-16668 You now require the registration of a filter bean.

Custom jpa repository method published by spring-data-rest

只愿长相守 提交于 2019-11-26 20:58:16
问题 I've added a custom method to a jpa repository as detailed on http://docs.spring.io/spring-data/data-jpa/docs/1.0.x/reference/html/#repositories.custom-implementations As far as I could see, this method is not exposed when I use spring-data-rest. Is there any way I could publish it as part of the REST API generated by spring-data-rest (without creating a Spring MVC Controller myself)? 回答1: I checked the code base - seems like they have explicitily disabled custom methods - not sure why. Here

Multiple Repositories for the Same Entity in Spring Data Rest

南笙酒味 提交于 2019-11-26 20:50:52
问题 Is it possible to publish two different repositories for the same JPA entity with Spring Data Rest? I gave the two repositories different paths and rel-names, but only one of the two is available as REST endpoint. The point why I'm having two repositories is, that one of them is an excerpt, showing only the basic fields of an entity. 回答1: The terrible part is not only that you can only have 1 spring data rest repository (@RepositoryRestResource) per Entity but also that if you have a regular

Spring Data REST: Override repository method on the controller

二次信任 提交于 2019-11-26 20:25:20
问题 I have the following REST repository, whose implementation is generated at runtime by Spring. @RepositoryRestResource public interface FooRepository extends CrudRepository<Foo, Long> { } This means that I will have save(), find(), exists() and other methods available and exposed via REST. Now, I would like to override one of the methods; for example, save(). For that, I would create a controller exposing that method, like so: @RepositoryRestController @RequestMapping("/foo") public class

How to use Spring managed Hibernate interceptors in Spring Boot?

血红的双手。 提交于 2019-11-26 20:08:42
Is it possible to integrate Spring managed Hibernate interceptors ( http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch14.html ) in Spring Boot? I'm using Spring Data JPA and Spring Data REST and need an Hibernate interceptor to act on an update of a particular field on an entity. With standard JPA events it's not possible to get the old values, and hence I think I need to use the Hibernate interceptor. Phil Webb There's not a particularly easy way to add a Hibernate interceptor that is also a Spring Bean but you can easily add an interceptor if it's manged entirely by Hibernate. To