17

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?

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
stratosgear
  • 942
  • 1
  • 16
  • 37
  • 3
    Mind if I ask what you ended up doing? I find myself in the exact same position as you. – Pytry Feb 02 '15 at 03:57

5 Answers5

17

To change the base URI, you can also just add this to application.properties:

spring.data.rest.base-path=/my/base/uri
ddewaele
  • 22,363
  • 10
  • 69
  • 82
Bruce Edge
  • 1,975
  • 1
  • 23
  • 31
12

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));
    }
}
gmich
  • 329
  • 2
  • 19
  • 1
    Much as it's frowned upon, I couldn't resist to add my "Thank You!" here: this saved a lot of head-scratching and you'd think that the Spring guys would have added this nugget of information to the reference documentation (or the Javadoc, or even the source code...) :) – Marco Massenzio Jan 03 '15 at 02:55
5

Correct application property is the following: spring.data.rest.base-path=/my/base/path (base-path instead of base-uri)

4

In spring boot 2

@Configuration
public class RepositoryConfiguration extends RepositoryRestConfigurerAdapter
{

   @Override
   public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config)
   {
      config.setBasePath("/my/base/uri");
   }
}
Ronan Quillevere
  • 3,699
  • 1
  • 29
  • 44
0

I think the path attribute is used to specify a path segment (so no slashes). The "/some/other/path" would have to be the servlet path or the context path (i.e. nothing to do with Spring Data).

Dave Syer
  • 56,583
  • 10
  • 155
  • 143
  • Yes, but still... How do I publish this resource in /some/other/path/item? I thought, that I could specify it with the ```path``` variable. It **is** Spring Data that publishes it, shouldn't it be configurable where? – stratosgear Jul 07 '14 at 10:55
  • You'd have to take that up with the Spring Data devs. It's published as a servlet resource, so you *can* do it as any path you want by changing the servlet mappings. But "/" is a special character in URIs, so I wouldn't be surprised if it was forbidden in the path attribute of the Spring Data annotation. Why does it matter? – Dave Syer Jul 07 '14 at 12:24