java 如何禁用 Spring Data REST 存储库的默认公开?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28330716/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to disable the default exposure of Spring Data REST repositories?
提问by gyoder
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 @EnableJpaRepositories
to implement their repository interfaces, but I only want to export the repositories in the parent project.
我有一个使用 spring-data-rest 的项目,并且有一个仅使用 Spring Data 的依赖项目。两个项目都有spring数据存储库,用于@EnableJpaRepositories
实现它们的存储库接口,但我只想导出父项目中的存储库。
Here's my question: is there some way to configure Spring Data REST to only expose rest endpoints for resources in the parent project, without having to explicitly annotate every repository in the dependency project with @RepositoryRestResource(exported = false)
?
这是我的问题:是否有某种方法可以将 Spring Data REST 配置为仅公开父项目中资源的其余端点,而不必使用@RepositoryRestResource(exported = false)
?
If I can only do this with @RepositoryRestResource
of disabling it, and worse yet, no other project with a different use case will be able to enable REST endpoints for those repositories, my dependency project will have to include Spring Data REST solely for the…
如果我只能通过@RepositoryRestResource
禁用它来做到这一点,更糟糕的是,没有其他具有不同用例的项目能够为这些存储库启用 REST 端点,那么我的依赖项项目将不得不仅包含 Spring Data REST 用于……
采纳答案by Oliver Drotbohm
Currently there's no global switch for what you're looking for. I've filed this ticketfor 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.
不确定它是否适合您,但除非明确注释,否则包私有存储库接口当前未公开。如果您可以使所有这些库存储库受到保护,则可能比显式注释更有利。
回答by Brian
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=annotatedto avoid default exposure.
在我寻找这个特定设置时循环回到这里。看起来现在已经实施了。在这种情况下,您需要设置spring.data.rest.detection-strategy=annotated以避免默认暴露。
All application.properties options:
所有 application.properties 选项:
# 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
参考