我有一个使用 spring-data-rest 的项目,并且有一个只使用 Spring Data 的依赖项目。两个项目都有spring数据仓库,都使用@EnableJpaRepositories
来实现它们的仓库接口(interface),但是我只想导出父项目中的仓库。
这是我的问题:是否有某种方法可以将 Spring Data REST 配置为仅公开父项目中资源的其余端点,而不必使用 @RepositoryRestResource(exported = false) 显式注释依赖项目中的每个存储库
?
如果我只能通过禁用它的 @RepositoryRestResource
来做到这一点,更糟糕的是,没有其他具有不同用例的项目能够为这些存储库启用 REST 端点,我的依赖项目将必须包含 Spring Data REST 仅用于……
最佳答案
在我寻找这个特定设置时循环回到这里。看起来现在已经实现了。在这种情况下,您需要设置 spring.data.rest.detection-strategy=annotated 以避免默认曝光。
所有 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
引用文献
关于java - 如何禁用 Spring Data REST 存储库的默认公开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28330716/