简体   繁体   中英

Change Resource Path in Spring Data REST

With Spring Data REST, I'd like to change the path of a specific resource to be under a prefix ie http://example.net/api/customprefix/myresource vs. http://example.net/api/myresource

I'm aware of how to change the base path of my Spring Data REST project using the spring.data.rest.base-path directive in application.properties , and this is currently set to /api

I have tried the following but I'm getting a 404 at http://example.net/api/customprefix/myresource

@RepositoryRestResource(path = "customprefix/myresource", collectionResourceRel = "myresources")
public interface MyResourceRepository extends PagingAndSortingRepository<MyResource, UUID> { }

Is it possible to set a custom prefix for a resource or group of resources with Spring Data REST?

What you want to do is not possible by design: you can read an extended version of why exactly here

Basically there is no reason why you would want to do this as the server or client doesn't need to know or understand the meaning of your URI. The customprefix has no meaning to the server or client whatsoever. You could just work with camel case or something like that to make your URI more readable.

In your case ie path = "customprefix-myresource" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM