spring-hateoas

How to disable RepositoryRestHandlerMapping and EndpointHandlerMapping?

杀马特。学长 韩版系。学妹 提交于 2019-11-29 17:19:28
问题 I am currently building an application with a REST interface, using Spring Boot, Hibernate and Spring-HATEOAS. My data model is defined as beans with @Entity annotation and I am using Spring's feature to automatically set up a Hibernate repository (Creating an interface extending PagingAndSortingRepository ). My application is completely annotation-driven, i.e., I have no web.xml but configure everything with the Spring annotations like @Configuration , @Bean etc., and start the application

HATEOAS on Spring Flux/Mono response

依然范特西╮ 提交于 2019-11-29 13:32:09
I've been using Spring HATEOAS following the guidelines: https://spring.io/guides/gs/rest-hateoas/#initial package hello; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*; import org.springframework.http.HttpEntity; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @RestController public class GreetingController { private static final String

Spring Data REST - Consume List of Entities, Java HATEOAS client

元气小坏坏 提交于 2019-11-29 11:41:24
I'm using Spring Data REST 2.5.1, Jackson 2.8.0, Spring Boot 1.3.6. I'm trying to retrieve a simple list of entities from my Repository via RestTemplate. I can hit the end point in a browser, and get the expected HAL data. Retrieving a single Entity works fine as below. These are all using the default SDR endpoints (e.g. localhost:{port}/myEntity). ResponseEntity<Resource<MyEntity>> responseEntity = new RestTemplate() .exchange( uri + "/1", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference<Resource<MyEntity>>() {}, port ) Or new RestTemplate().getForEntity(uri + "/1", MyEntity

Resolving entity URI in custom controller (Spring HATEOAS)

霸气de小男生 提交于 2019-11-29 05:36:40
I have a project based on spring-data-rest and also it has some custom endpoints. For sending POST data I'm using json like { "action": "REMOVE", "customer": "http://localhost:8080/api/rest/customers/7" } That is fine for spring-data-rest, but does not work with a custom controller. for example: public class Action { public ActionType action; public Customer customer; } @RestController public class ActionController(){ @Autowired private ActionService actionService; @RestController public class ActionController { @Autowired private ActionService actionService; @RequestMapping(value = "/customer

HATEOAS paths are invalid when using an API Gateway in a Spring Boot app

给你一囗甜甜゛ 提交于 2019-11-29 02:16:55
I have two spring boot applications where one of them is acting as an API Gateway (as discussed here Spring Example ). The other which is wired into the first one is exposing a profile service using spring-data-rest (spring-data-neo4j-rest). The first application is starting on port 8080 and is using zuul to route requests to the second as follows: zuul: routes: profiles: path: /profiles/** url: http://localhost:8083/profiles/ This all works fine and requests to http://localhost:8080/profiles are being served from the second app. The problem though is that the HATEOAS links in the response are

How to remove the “_embedded” property in Spring HATEOAS

▼魔方 西西 提交于 2019-11-29 00:57:36
问题 I'm using Spring Boot and HATEOAS to build a REST API and when my API returns a collection, it is wrapped inside a "_embedded" property, like so: { "_links":{ "self":{ "href":"http://localhost:8080/technologies" } }, "_embedded":{ "technologies":[ { "id":1, "description":"A", "_links":{ "self":{ "href":"http://localhost:8080/technologies/1" } } }, { "id":2, "description":"B", "_links":{ "self":{ "href":"http://localhost:8080/technologies/2" } } } ] } } I want the response to be like this: { "

How to change HAL links format using Spring HATEOAS

孤街浪徒 提交于 2019-11-28 21:15:32
I'm building a Spring REST application using Spring HATEOAS (0.16.0.RELEASE) and I'd like the JSON links output to look like: _links: { self: { href: "https://<ip>/api/policies/321" } } while it renders like: "links": [{ "rel":"self", "href":"http://<ip>/api/policies/321" }] I'm using HATEOAS Resource and ResourceAssembler . Why do I get this format instead of the other? How can I change it? In order to use HAL as the message format language for our RESTful API, and enable automatic pagination, we need some configuration changes in our applicaiton. Since Spring Data and Spring HATEOAS already

Custom response for root request int the Spring REST HATEOAS with both RepositoryRestResource-s and regular controllers

余生长醉 提交于 2019-11-28 17:03:38
Let's say I have two repositories: @RepositoryRestResource(collectionResourceRel = "person", path = "person") public interface PersonRepository extends PagingAndSortingRepository<Person, Long> { List<Person> findByLastName(@Param("name") String name); } and @RepositoryRestResource(collectionResourceRel = "person1", path = "person1") public interface PersonRepository1 extends PagingAndSortingRepository<Person1, Long> { List<Person1> findByLastName(@Param("name") String name); } with one regular controller: @Controller public class HelloController { @RequestMapping("/hello") @ResponseBody public

How do I avoid n+1 queries with Spring Data Rest?

老子叫甜甜 提交于 2019-11-28 15:23:45
问题 Question. How do I avoid n+1 queries with Spring Data REST? Background. When querying Spring Data REST for a list of resources, each of the resulting top-level resources has links to the associated resources, as opposed to having the associated resources embedded directly in the top-level resources. For example, if I query for a list of data centers, the associated regions appear as links, like this: { "links" : [ { "rel" : "self", "href" : "http://localhost:2112/api/datacenters/1" }, { "rel"

Spring Rest: Cannot insert rows that have @ManyToOne column

半世苍凉 提交于 2019-11-28 11:42:36
问题 I am following a spring getting started tutorial in https://spring.io/guides/gs/accessing-data-rest/ I added another entity books that has @ManyToOne relation to Person entity. Person entity has a new property called bikes and has a @OneToMany relation with Bike entity. Only thing that is different from the getting started project is the new attribute with its getter and setter: package hello; import java.util.List; import javax.persistence.Entity; import javax.persistence.GeneratedValue;