Vijay Kumar Rajput
Vijay Kumar Rajput

Reputation: 1121

spring rest data plural url

I have a domain class called StoreType.java which is exposed by below spring repository

public interface StoreTypeRepository extends PagingAndSortingRepository<StoreType, Short> {

}

When I access this using url http://localhost:8080/my-persistence/jpa/storetypes it returns 404.

if I change my domain class as Storetype (without camel case), it works fine and return 200 OK.

I have few more repositories which uses single world domain classes like Store.java , Country.java and these work fine and by default these exposed as plural of domain class name.

I know spring exposed url as plural of domain classes but not sure why it is not exposing it. I can override this using @RepositoryRestResource(path="/storetypes") but I want to know what is default rest url if domain classes name in camel case.

Upvotes: 1

Views: 2124

Answers (1)

Edward J Beckett
Edward J Beckett

Reputation: 5140

You seem to have answered the question to your problem by specifying the @RepositoryRestResource( path="/storetypes" ) annotation as the documentation states.

Spring Data REST exposes a collection resource named after the uncapitalized, pluralized version of the domain class the exported repository is handling. Both the name of the resource and the path can be customized using the @RepositoryRestResource on the repository interface.

In this case your naming convention seems correct using StoreTypeRepository however one thing confuses me about your repository definition... I'm not sure why you set the type parameter to the PagingAndSortingRepository<StoreType, Short> but I'm quite certain that's incorrect as the second type parameter should be of type Long.

Upvotes: 1

Related Questions