Home > Enterprise >  Exclude entities for Spring Data Rest
Exclude entities for Spring Data Rest

Time:05-17

I'm using Spring Data Rest in one of my projects, and Spring Data Rest will create an HTTP endpoint for each of my entities. There's a few entities which I'd like to exclude form this scanning however. Is there an option to do so?

CodePudding user response:

Spring data rest uses Spring HATEOAS. See https://www.baeldung.com/spring-data-rest-customize-http-endpoints .

You can exclude entities from scanning by adding @RestResource(exported = false) annotation:

    @RestResource(exported = false)
    public class User {}

CodePudding user response:

To disable the endpoint for entity Order, add @RepositoryRestResource(exported = false) to its repository interface.

@RepositoryRestResource(exported = false)
public interface OrderRepository extends CrudRepository<Order, Long> { }

See more configuration in https://docs.spring.io/spring-data/rest/docs/current/reference/html/#getting-started.setting-repository-detection-strategy

  • Related