I cannot seem to be able to map my Repository in any location other than the following:
@RepositoryRestResource(collectionResourceRel = "item", path = "item")
public interface ItemRepository extends PagingAndSortingRepository<Item, Long> {
I thought I can use:
path = "/some/other/path/item"
but the mapping does not resolve. I get:
HTTP ERROR 404
Problem accessing /some/other/path/item. Reason:
Not Found
In spring-data javadoc path
is defined as: "The path segment under which this resource is to be exported."
What am I doing wrong?
The @RepositoryRestResource annotation is optional and is used to customize the REST endpoint. If we decided to omit it, Spring would automatically create an endpoint at “/websiteUsers” instead of “/users“. That's it! We now have a fully-functional REST API.
It is not recommended in real-world applications as you are exposing your database entities directly as REST Services. While designing RESTful services, the two most important things that we consider are the domain model and the consumers. But, while using Spring Data REST, none of these parameters are considered.
Annotation Type RepositoryRestControllerAnnotation to demarcate Spring MVC controllers provided by Spring Data REST. Allows to easily detect them and exclude them from standard Spring MVC handling.
and collectionResourceRel is described: The rel value to use when generating links to the collection resource.
To change the base URI, you can also just add this to application.properties:
spring.data.rest.base-path=/my/base/uri
You need to extend the RepositoryRestMvcConfiguration
and override the configureRepositoryRestConfiguration(RepositoryRestConfiguration config)
to set yours baseUri
. e.g.
@Configuration
public class MyRepositoryRestMvcConfiguration extends RepositoryRestMvcConfiguration {
private static final String MY_BASE_URI_URI = "/my/base/uri";
@Override
protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
super.configureRepositoryRestConfiguration(config);
config.setBaseUri(URI.create(MY_BASE_URI_URI));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With