To change the base path in Spring Data Rest is relatively easy, you just add spring.data.rest.baseUri=api or spring.data.rest.basePath=/api if you have Spring Boot 1.2.3+ in application.properties and then your base
path to Spring Data Rest would be at localhost:8080/api.
But unfortunately for me it didn’t work. Thanks to raised issue on github I found out that the problem was in my custom config which I used to expose ids of the entities:
@Configuration
public class ExposeIdsConfig extends RepositoryRestMvcConfiguration {
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.exposeIdsFor(Role.class);
config.exposeIdsFor(OrgUnit.class);
}
}So if you extend the configuration it wipes settings which were set up in .properties file. The solution is to set base path in this config:
@Configuration
public class ExposeIdsConfig extends RepositoryRestMvcConfiguration {
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.exposeIdsFor(Role.class);
config.exposeIdsFor(OrgUnit.class);
config.setBasePath("/api");
}
}Another solution is to extend RepositoryRestConfigurerAdapter instead of RepositoryRestMvcConfiguration. In this case you’ll be able to use spring.data.rest.basePath=/api property.