How to disable the default exposure of Spring Data REST repositories?

前端 未结 2 1439
抹茶落季
抹茶落季 2020-12-08 07:57

I have a project that uses spring-data-rest, and has a dependency project that only uses Spring Data. Both projects have spring data repositories and use @EnableJpaRep

相关标签:
2条回答
  • 2020-12-08 08:14

    Currently there's no global switch for what you're looking for. I've filed this ticket for you for inclusion in the next major release.

    Not sure if it is an option for you but package private repository interfaces are not currently exposed unless explicitly annotated. If you can make all those library repositories package protected that might be favorable over the explicit annotation.

    0 讨论(0)
  • Looping back here as I was looking for this specific setting. It looks like this is now implemented. In this case, you would want to set spring.data.rest.detection-strategy=annotated to avoid default exposure.

    All application.properties options:

    # Exposes all public repository interfaces but considers @(Repository)RestResource\u2019s `exported flag.
    spring.data.rest.detection-strategy=default
    
    # Exposes all repositories independently of type visibility and annotations.
    spring.data.rest.detection-strategy=all
    
    # Only repositories annotated with @(Repository)RestResource are exposed, unless their exported flag is set to false.
    spring.data.rest.detection-strategy=annotated
    
    # Only public repositories annotated are exposed.
    spring.data.rest.detection-strategy=visibility
    

    References

    • 3.5.1. Setting the Repository Detection Strategy
    • Common Application Properties
    0 讨论(0)
提交回复
热议问题