spring-data-rest

Spring Data Rest: Return Resources of User

房东的猫 提交于 2019-11-30 07:45:56
I'm creating a simple CRUD-App (a shoppinglist) with Spring Boot and Spring Data Rest. I have a resource: ShoppingItem . Is there an easy way to only return the resources which belong to the user who send the request? (Multiple User support) So a User only get his own ShoppingItems and not every ShoppingItem. Or do i have to implement a Controller by myself, where i do this? I found Spring Data REST filtering data based on the user this approach for filtering resources based on the user, but this won't help me for the repository endpoint. Thanks in advance If you are using Spring security

Modify SQL query generated behind Spring Data REST projections

旧时模样 提交于 2019-11-30 07:41:41
EDIT : How to Keep only needed columns in SELECT for Spring Data Rest Projections? Spring Data Rest Projections are good for getting a subset of columns for links which are generated, but the Query that gets generated in behind still has all columns in it. How can Projections be created where also SQL queries have only those columns in SELECT which are in Projection I don't know why it's missing from the docs, but this spring sample (from spring) shows that you can use projections as the return type for a @Query. So you can do: public interface ActionId { String getId(); } @Query("select a.id

Spring Data Rest base path

自作多情 提交于 2019-11-30 06:39:04
I have added Spring Data Rest (2.0) to an existing Spring MVC application by creating a Java config class that extends RepositoryRestMvcConfiguration, and adding @RestResource to the repositories. Is it possible to change the base URL for the Rest API? E.g: http://localhost:8080/rest/customers instead of http://localhost:8080/customers I tried to override configureRepositoryRestConfiguration using setBaseURI, but it didn't seem to apply to all links in the response. As of Spring Boot 1.2 you are able to set this property: spring.data.rest.baseUri=api Alternatively: spring.data.rest.base-uri

Rest Controllers vs spring-data-rest RepositoryRestResource

人盡茶涼 提交于 2019-11-30 05:42:44
问题 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

How to add elements in a many-to-many relationship via Spring's @RepositoryRestResource REST API?

雨燕双飞 提交于 2019-11-30 05:36:51
问题 I'm having trouble figuring out exactly how to use the @RepositoryRestResource interface to create many-to-many relationships between two fairly simple entities. For example, I have a simple parent-child entity relationship like this: @Entity public class ParentEntity { @Id @GeneratedValue private Long id; @ManyToMany private List<ChildEntity> children; } @Entity public class ChildEntity { @Id @GeneratedValue private Long id; @ManyToMany(mappedBy="children") private List<ParentEntity> parents

Spring Interceptor not working in Spring Data REST URLs

北城余情 提交于 2019-11-30 05:35:33
问题 I am working on a project with Spring Data Rest and JPA and I am trying to configure an HTTP interceptor. As per the reference docs, available in Spring Web MVC Docs - Handler Mapping Interceptor, I created a component that extends HandlerInterceptorAdapter as follows: @Component public class DBEditorTenantInterceptor extends HandlerInterceptorAdapter { Logger logger = LoggerFactory.getLogger(DBEditorTenantInterceptor.class); @Override public boolean preHandle(HttpServletRequest request,

Custom Spring MVC HTTP Patch requests with Spring Data Rest functionality

做~自己de王妃 提交于 2019-11-30 05:21:40
问题 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? 回答1: I do not think you can use the

Can't POST a collection

喜夏-厌秋 提交于 2019-11-30 04:55:19
问题 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

Spring Boot @RepositoryEventHandler not invoked

雨燕双飞 提交于 2019-11-30 04:20:02
问题 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

Spring Data REST - Detected multiple association links with same relation type

倾然丶 夕夏残阳落幕 提交于 2019-11-30 03:10:58
问题 I am trying to doing a simple Spring app. It needs to expose REST endpoints and save it to a relational database. I took your sample project, http://spring.io/guides/gs/accessing-data-rest/. I am able to do all the operations( POST, PATCH, PUT, GET) as mentioned in your guide. However I tried creating adding relationships to Person Entity class and things start to fall apart. @Entity public class Person { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; private String