spring-data-rest

Spring Data Rest and custom repositories

心已入冬 提交于 2019-12-07 08:17:16
问题 Is it possible to export REST resources with custom (spring data) repositories? How does it work? I cannot find any example. I also have not found any claim that it is impossible. 回答1: Spring data rest specifically detects and does not export custom implementations on repositories. See the reference to the codebase here and the reason why here. If you want to expose a custom repository implementation, you will need to use a custom controller. Documentation for how to appropriately use custom

Handling custom exceptions (i18n) with Spring Data REST

一笑奈何 提交于 2019-12-07 07:08:40
问题 I'm using Spring Boot 1.5.4 with Spring JPA, Spring Data REST, HATEOAS... I'm looking for a best practice (Spring way) to customize exceptions Spring Data REST is managing adding the i18n support. I looked at the class MessageException (https://github.com/spring-projects/spring-data-rest/blob/master/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/ExceptionMessage.java) as start point. A typical Spring Data REST exception is very nice: { "timestamp": "2017-06

Spring Data Rest: Override Method in RestController with same request-mapping-path

拜拜、爱过 提交于 2019-12-07 05:50:32
问题 Given the following working repository in our application: public interface PersonRepository extends PagingAndSortingRepository<Person, Integer> { } The Repository is exposed via spring-data-rest with URI "/api/persons" and works as expected. We now want to override the post-method of the repository in a method of a RestController: @RestController @RequestMapping("/persons") public class PersonController { @RequestMapping(value = "/**", method = RequestMethod.POST, produces = MediaType

Spring Data REST and custom entity lookup (Provided id of the wrong type)

Deadly 提交于 2019-12-07 03:58:48
问题 I have a model that looks something like this: @Entity public class MyModel { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(unique = true, nullable = false) @RestResource(exported = false) private int pk; @Column(unique = true, nullable = false) private String uuid = UUID.randomUUID().toString(); @Column(nullable = false) private String title; public int getPk() { return pk; } public void setPk(int pk) { this.pk = pk; } public String getUuid() { return uuid; } public void

Changing the JSON format for spring-data-rest

半世苍凉 提交于 2019-12-07 02:32:13
问题 Currently spring-data-rest is returning JSON in HAL format in a spring-boot project of mine. I am using an ember.js frontend and want to use jsonapi (http://jsonapi.org/) specification. How might I register a new JSON formatting strategy given I will need to write the formatter myself as one does not exists yet? 回答1: This is how you can customize the HATEOAS that Spring Data REST produces: https://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.customizing-json

Spring Data Rest Override Repositories (Controllers vs AOP)

放肆的年华 提交于 2019-12-07 01:58:34
Domain/Repository Project { User owner; } //Querydsl repositories @RepositoryRestResource public interface ProjectRepository extends PagingAndSortingRepository<Project, Long>, QueryDslPredicateExecutor<Project>, QuerydslBinderCustomizer<QProject> { default void customize(QuerydslBindings bindings, QProject project) { (...) } } Requeriment: filter data according to the authenticated user context: If user is ROLE_PUBLIC show projects according predicate and where user is the owner . If user is ROLE_ADMIN show projects according predicate filter. I tried solved throught several alternatives:

How to disable paging for JpaRepository in spring-data-rest

孤者浪人 提交于 2019-12-06 22:13:55
问题 I'm using spring-data-rest with JpaRepository to create the Rest-Endpoints. By default, paging is enabled for all JpaRepository , what is a good thing. But I have a legacy application that we port to our new stack that does not support paging. I would like to disable paging depending on an URL-Parameter to still be able to use paging in new application code. I tried various approaches to expose the resources with and without paging: Use CrudRepository : Results in only having an unpaged

Spring Data Rest: custom Converter<Entity, Resource> is never invoked

主宰稳场 提交于 2019-12-06 16:41:50
I'm trying to implement a custom Converter for an Entity to a Resource object with Spring Data Rest, but the Converter is never invoked. I'm following this documentation : If your project needs to have output in a different format, however, it’s possible to completely replace the default outgoing JSON representation with your own. If you register your own ConversionService in the ApplicationContext and register your own Converter, then you can return a Resource implementation of your choosing. That's what I've tried to do. I have a @Configuration class that extends

RepositoryRestResource with spring-boot CLI

爷,独闯天下 提交于 2019-12-06 16:35:15
I'm trying to implement a simple REST service based on a JPA repository with spring-boot and spring-data-rest. (see this tutorial ) The following code works quite well if a use it with gradle: package ch.bfh.swos.bookapp import org.springframework.boot.SpringApplication import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.context.annotation.* import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration import org.springframework.data.jpa.repository.config.EnableJpaRepositories import org.springframework.context.annotation.Import

Avoid showing Spring Framework specific services as part of Swagger interface

ε祈祈猫儿з 提交于 2019-12-06 15:44:31
I am using spring-boot-starter-parent 1.3.3.RELEASE. I am unable to disable the following endpoints in Swagger UI. Need To Disable:- Entity Metadata Services profile-controller repository-controller I disabled the following endpoints using the code.. Disabled endpoints:- environment-manager-mvc-endpoint generic-postable-mvc-endpoint restart-mvc-endpoint Code:- public Docket appHierarchyServiceApi() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(Predicates.not(RequestHandlerSelectors.basePackage("org.springframework.boot"))) .paths(PathSelectors.any()).build() How to disable