如何禁用Spring Data REST存储库的默认曝光?

我有一个使用spring-data-rest的项目,并且有一个只使用Spring Data的依赖项目。 这两个项目都有spring数据存储库并使用@EnableJpaRepositories来实现它们的存储库接口,但我只想在父项目中导出存储库。

这是我的问题:是否有一些方法可以将Spring Data REST配置为仅公开父项目中资源的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 

参考: 4.6.1。 哪些存储库默认公开?