解决此问题的一种方法是替换存储库检测策略。
@Component
@ConfigurationProperties("app.repository")
@Data
public class AppRepositoryConfig {
private boolean exportStudy = true;
private boolean exportSample = true;
...
}
其次,修改库存检测策略(stock RepositoryDetectionStrategy)的行为,以考虑您的配置:
@Configuration
@RequiredArgsConstructor
public class AppRepositoryDetectionStrategyConfig extends RepositoryRestConfigurerAdapter {
@NonNull private AppRepositoryConfig appRepositoryConfig;
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
RepositoryDetectionStrategy rds = config.getRepositoryDetectionStrategy();
config.setRepositoryDetectionStrategy(
repositoryDetectionStrategy(rds)
);
}
private RepositoryDetectionStrategy repositoryDetectionStrategy(
RepositoryDetectionStrategy repositoryDetectionStrategy) {
RepositoryDetectionStrategy rds = metadata -> {
boolean defaultExportSetting = repositoryDetectionStrategy.isExported(metadata);
if (metadata.getDomainType().equals(Study.class)) {
return (appRepositoryConfig.isExportStudy()) ? defaultExportSetting : false;
}
...
return defaultExportSetting;
};
return rds;
}