spring-data-rest

Rest Controllers vs spring-data-rest RepositoryRestResource

可紊 提交于 2019-11-30 22:01:06
I know this might feel like a duplicate of this. When to use @RestController vs @RepositoryRestResource But I have a few things which were not addressed in that question. With @RepositoryRestResource , every method is by default exposed. Which I feel is a bit annoying. Correct me if I am wrong here. For example in the below case @RepositoryRestResource public interface ProductRepository extends MongoRepository<Product, String> {} If I want only findAll() and findOne() to be exposed and not any other methods, especially delete. To achieve this I need to do something like this

Canonical _links with Spring HATEOAS

好久不见. 提交于 2019-11-30 21:42:58
We're building a RESTful web service similiar to the spring.io guide " Accessing JPA Data with REST ". To reproduce the sample outputs below, it suffices to add a ManyToOne -Relation to Person as follows: // ... @Entity public class Person { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; private String firstName; private String lastName; @ManyToOne private Person father; // getters and setters } A GET request after adding some sample data yields: { "firstName" : "Paul", "lastName" : "Mustermann", "_links" : { "self" : { "href" : "http://localhost:8080/people/1" }, "father

Custom Spring MVC HTTP Patch requests with Spring Data Rest functionality

。_饼干妹妹 提交于 2019-11-30 21:00:00
What is the best practice for supporting HTTP PATCH in custom Spring MVC controllers? Particularly when using HATEOAS/HAL? Is there an easier way to merge objects without having to check for the presence of every single field in the request json (or writing and maintaining DTOs), ideally with automatic unmarshalling of links to resources? I know this functionality exists in Spring Data Rest, but is it possible to leverage this for use in custom controllers? I do not think you can use the spring-data-rest functionality here. spring-data-rest is using json-patch library internally. Basically I

Can't POST a collection

▼魔方 西西 提交于 2019-11-30 20:46:50
I have a simple Entity with a single collection mapped. @Entity public class Appointment Identifiable<Integer> { @Id @GeneratedValue(strategy = GenerationType.AUTO) @JsonIgnore private Integer id; @Column(name="TRAK_NBR") private String trackNumber; @OneToMany(fetch =FetchType.EAGER, cascade= CascadeType.ALL) @JoinColumn(name="CNSM_APT_VER_WRK_I", nullable = false) private Set<Product> products = new HashSet<Product>(); } @Entity public class Product implements Identifiable<Integer> { @Id @Column(name = "CNSM_PRD_VER_WRK_I") @GeneratedValue(strategy = GenerationType.AUTO) @JsonIgnore private

Spring Boot @RepositoryEventHandler not invoked

前提是你 提交于 2019-11-30 19:42:11
I've got a @RepositoryEventHandler set up and it is not being invoked for some unknown reason. @Component @RepositoryEventHandler(User.class) public class UserEventHandler { @Autowired private PasswordCrypto passwordCrypto; @HandleBeforeSave public void handleUserSave(User user) { if (user.getPassword() != null && !"".equals(user.getPassword())) { user.setPassword(passwordCrypto.encrypt(user.getPassword())); } } @HandleBeforeCreate public void handleUserCreate(User user) { user.setPassword(passwordCrypto.encrypt(user.getPassword())); } } The Repository: public interface UserRepository extends

Two Maven Dependency for latest and old version conflicts

孤街浪徒 提交于 2019-11-30 19:39:23
Am using spring-data-dynamoDB project from here , as per its pom.xml they have used 1.6.9.1 version of aws-java-sdk , but I need to use latest version of aws-java-sdk for my project for using some of its features to implement Amazon s3 too. If I include its dependency, <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk</artifactId> <version>1.7.9</version> </dependency> am getting an exception as follows, 12:51:25.298 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)': [_relProvider] 12:51:25.307 [main] ERROR o.s.w.c

Optionally disable HATEOAS format in Spring Data Rest

自古美人都是妖i 提交于 2019-11-30 18:02:05
So let's say I have an existing application that has two endpoints /people and /pants. Calling GET /people returns: [ { "name":"john", "age":37, "pants":[ { "color":"green", "brand":"levis", "size":"medium" }, { "color":"indigo", "brand":"jncos", "size":"medium-with-huge-legs" } ] }, { "name":"june", "age":23, "pants":[ { "color":"pink", "brand":"gap", "size":"small" } ] } ] If i were to use Spring Data Rest and call GET /person i'd receive something like: { "_links":{ "next":{ "href":"http://myapp.com/people?page=1&size=20" }, "self":{ "href":"http://myapp.com/people{&page,size,sort}",

Why is DELETE not supported on to-many-association resources in Spring Data REST?

百般思念 提交于 2019-11-30 16:08:34
I am using Spring Data REST. I am trying to unbind a collection association from an entity (item). i.e. - a property of the item is of List type. I want to remove all items from that List . To do this, I am using the DELETE method: curl -X DELETE …/categories/54ea0bcf27a2fb1b4641083a/fixedParentCategories This gives me a 405 Method not allowed error code. But, it works for a single valued association (when it is not of List type). The documentation clearly lists DELETE as a supported method for associations. I'd like to know if there is a way around this. Also, I tried using PUT (Content-Type:

How to establish relationships between Spring Data REST / Spring HATEOAS based (micro) services?

不羁岁月 提交于 2019-11-30 14:03:59
Trying to figure out a pattern for how to handle relationships when using a hypermedia based microservices based on Spring Data Rest or HATEOAS. If you have service A (Instructor) and Service B (Course) each exist as an a stand alone app. What is the preferred method for establishing a relationship between the two services. In a manner that does not require columns for IDs of the foreign service. It would be possible for each service to have many other services that need to communicate in the same manor. Possible solution (Not sure a correct path) Each service has a second table with a

Spring Data REST - POST new entity with relationships

自古美人都是妖i 提交于 2019-11-30 13:50:48
问题 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