spring-data-rest

Spring data rest validation + exception mapper: confusing

和自甴很熟 提交于 2019-12-08 02:58:32
问题 I am using Spring Data Rest and all is going well. I want to apply validation (JSR 303) on my entities. The spring docs say I can intercept application events in a few ways (none of which I can get to work, and right now spring.io seems to be down). However, I did get it working by putting @Validated on my respository: @Validated @RepositoryRestResource(collectionResourceRel = "workers", path = "workers") public interface WorkerRepository extends PagingAndSortingRepository<Worker, Long> { }

Javers - What are advantages of using Javers instead of Envers?

谁都会走 提交于 2019-12-08 02:52:01
问题 I am developing a RESTful API using Spring Data REST. Now for auditing, Spring does have the option to auditing meta data like created_date and modified_date but they don't provide entity versioning. Currently there are two popular libraries for entity version which are Envers and Javers. I have looked over for a comparison of both but there arent any articles on this matter. So what are the benefits and drawbacks of using Javers over Envers? 回答1: There are two big difference between JaVers

E11000 duplicate key error when doing PUT for modifiable resource with Spring Data Rest

痴心易碎 提交于 2019-12-08 01:20:18
问题 Update: According to this question, the author of Spring data rest say, the @Version properties will become ETags in response header. And there are two options for update: Just PUT without an If-Match header -- enforces overriding whatever is present on the server as the aggregate gets loaded, incoming data mapped onto it and it written back. You still get optimistic locking applied if another client changed the aggregate in the meantime (although an admittedly very short window). If that's

Reconfigure Spring Data Rest to Index at Page 1

冷暖自知 提交于 2019-12-07 22:14:05
问题 I thought I had this figured out but the setting does not seem to change the index. setOneIndexedParameters(true) @Configuration @EnableWebMvc public class WebMvcConfig extends WebMvcConfigurerAdapter { @Override public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) { PageableHandlerMethodArgumentResolver resolver = new PageableHandlerMethodArgumentResolver(); resolver.setOneIndexedParameters(true); argumentResolvers.add(resolver); super.addArgumentResolvers

Spring Data REST returns http 405 asking for List of nested resources

喜夏-厌秋 提交于 2019-12-07 19:59:26
问题 I'm using Spring Boot 1.5.7, Spring Data REST, Spring HATEOAS, Hibernate, Spring Validation, Swagger. I'm exposing all my repositories via Spring Data REST. It works quite fine but I've a problem when I expose a nested list of objects. Let's see this example: @Entity public class TicketBundle extends AbstractEntity { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY,mappedBy="ticketBundle") @OnDelete(action = OnDeleteAction.NO_ACTION) private List

Spring Data REST: How to retrieve many items using list of Ids in one single call?

霸气de小男生 提交于 2019-12-07 17:45:33
问题 I can retrieve one single book from Spring Data REST with a call such as: GET /book/{id} Now, if I know the Ids of two books and I want to retrieve them all at once? What should the call be? I tried the following but it is returning me different books than the specified ones: GET /book?ids=id1,id2 回答1: You could declare a query method in your Repository interface like this: List<Book> findByIdIn(@Param("ids") Long[] ids); So that you can request books this way: GET /book/search/findByIdIn?ids

Spring Boot Keycloak - How to get a list of roles assigned to a user?

只谈情不闲聊 提交于 2019-12-07 16:36:31
问题 I am trying to get a list of roles assigned to a particular user from a Spring Boot application secured with keycloak. I have declared an AccessToken bean in the KeycloakWebSecurityConfigurerAdapter configuration class as follows: @Configuration @EnableWebSecurity @ComponentScan(basePackageClasses = KeycloakSecurityComponents.class) public class KeycloakSecurityConfig extends KeycloakWebSecurityConfigurerAdapter { //other config code @Bean @Scope(scopeName = WebApplicationContext.SCOPE

How to set the default media type for spring-data-rest?

纵饮孤独 提交于 2019-12-07 16:18:45
问题 From RepositoryRestConfiguration I can see that setting spring.data.rest.default-media-type=application/json could change the default media type served by @RepositoryRestResource . @SuppressWarnings("deprecation") public class RepositoryRestConfiguration { private MediaType defaultMediaType = MediaTypes.HAL_JSON; } Question: as this class is in deprecation , what is the correct way to set/override the default type? 回答1: You can do this via RepositoryRestConfiguration or simply with a property

LocalDateTime is not converted to String but to Json object

懵懂的女人 提交于 2019-12-07 13:22:42
问题 I want to serialize a creation date of type java.time.LocalDateTime as String, when calling a spring-data-rest service. The field of the entity is annotated with DateTimeFormat(iso=ISO.DATE_TIME). I also registered a LocalData to String Converter in the Spring Configuration class. @Override @Bean protected ConversionService neo4jConversionService() throws Exception { ConversionService conversionService = super.neo4jConversionService(); ConverterRegistry registry = (ConverterRegistry)

Deleting an association over REST in Spring Data REST+HATEOAS

一笑奈何 提交于 2019-12-07 11:56:55
问题 I wish to know how to delete a many-to-many association via a REST call. I am able to create records, and associated them, but do not understand how to delete. I have a Spring Boot project where i'm using REST and HATEOAS to by pass Services and Controllers and expose my Repository directly. I have a User Model/Domain class @Entity @Table(name = "usr") public class User implements Serializable { private static final long serialVersionUID = 1L; @Version private long version = 0; @Id