Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data Rest base path

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.

like image 870
Jaffa Avatar asked Feb 25 '14 19:02

Jaffa


People also ask

What does spring data rest do?

Spring Data REST builds on top of Spring Data repositories, analyzes your application's domain model and exposes hypermedia-driven HTTP resources for aggregates contained in the model.

What does the @RepositoryRestResource annotation do?

@RepositoryRestResource is used to set options on the public Repository interface - it will automatically create endpoints as appropriate based on the type of Repository that is being extended (i.e. CrudRepository/PagingAndSortingRepository/etc).

What is @RestController in spring boot?

Spring RestController annotation is a convenience annotation that is itself annotated with @Controller and @ResponseBody . This annotation is applied to a class to mark it as a request handler. Spring RestController annotation is used to create RESTful web services using Spring MVC.


1 Answers

As of Spring Boot 1.2 you are able to set this property:

spring.data.rest.baseUri=api

Alternatively:

spring.data.rest.base-uri=api

(Spring Boot uses a relaxed binding system)

NOTE: I have found that if you have extended RepositoryRestMvcConfiguration with custom configuration, the property does not take effect. For more information see:

https://github.com/spring-projects/spring-boot/issues/2392

Once the next version of Spring Boot is released (after 1.2.1), the solution will be to extend RepositoryRestMvcBootConfiguration instead.

like image 98
JBCP Avatar answered Sep 20 '22 17:09

JBCP