From 015335d9eff0a38da54f7b90da44687ccff7ea1f Mon Sep 17 00:00:00 2001 From: "Greg L. Turnquist" Date: Mon, 15 Mar 2021 16:30:09 -0500 Subject: [PATCH] Replace RepositoryRestConfigurerAdapter in the ref docs. RepositoryRestConfigurerAdapter was superceded by RepositoryRestConfigurer and its default methods a long time ago. Update the ref docs to properly use the new interface. Fixes #1983. --- src/main/asciidoc/configuring-cors.adoc | 6 +++--- src/main/asciidoc/getting-started.adoc | 10 +++++----- src/main/asciidoc/validation.adoc | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/asciidoc/configuring-cors.adoc b/src/main/asciidoc/configuring-cors.adoc index 01a231456..0965fe3fe 100644 --- a/src/main/asciidoc/configuring-cors.adoc +++ b/src/main/asciidoc/configuring-cors.adoc @@ -65,12 +65,12 @@ The following example sets an allowed origin, adds the PUT and DELETE HTTP metho [source, java] ---- @Component -public class SpringDataRestCustomization extends RepositoryRestConfigurerAdapter { +public class SpringDataRestCustomization implements RepositoryRestConfigurer { @Override - public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { + public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config, CorsRegistry cors) { - config.getCorsRegistry().addMapping("/person/**") + cors.addMapping("/person/**") .allowedOrigins("http://domain2.example") .allowedMethods("PUT", "DELETE") .allowedHeaders("header1", "header2", "header3") diff --git a/src/main/asciidoc/getting-started.adoc b/src/main/asciidoc/getting-started.adoc index 1208c808f..07d9b827c 100644 --- a/src/main/asciidoc/getting-started.adoc +++ b/src/main/asciidoc/getting-started.adoc @@ -80,7 +80,7 @@ Spring Data REST configuration is defined in a class called `RepositoryRestMvcCo IMPORTANT: This step is unnecessary if you use Spring Boot's auto-configuration. Spring Boot automatically enables Spring Data REST when you include *spring-boot-starter-data-rest* and, in your list of dependencies, your app is flagged with either `@SpringBootApplication` or `@EnableAutoConfiguration`. -To customize the configuration, register a `RepositoryRestConfigurer` (or extend `RepositoryRestConfigurerAdapter`) and implement or override the `configure…`-methods relevant to your use case. +To customize the configuration, register a `RepositoryRestConfigurer` and implement or override the `configure…`-methods relevant to your use case. Make sure you also configure Spring Data repositories for the store you use. For details on that, see the reference documentation for the https://projects.spring.io/spring-data/[corresponding Spring Data module]. @@ -133,10 +133,10 @@ class CustomRestMvcConfiguration { @Bean public RepositoryRestConfigurer repositoryRestConfigurer() { - return new RepositoryRestConfigurerAdapter() { + return new RepositoryRestConfigurer() { @Override - public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { + public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config, CorsRegistry cors) { config.setBasePath("/api"); } }; @@ -151,10 +151,10 @@ Alternatively, you can register a custom implementation of `RepositoryRestConfig [source,java] ---- @Component -public class CustomizedRestMvcConfiguration extends RepositoryRestConfigurerAdapter { +public class CustomizedRestMvcConfiguration extends RepositoryRestConfigurer { @Override - public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { + public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config, CorsRegistry cors) { config.setBasePath("/api"); } } diff --git a/src/main/asciidoc/validation.adoc b/src/main/asciidoc/validation.adoc index c990a5a70..c7442f0be 100644 --- a/src/main/asciidoc/validation.adoc +++ b/src/main/asciidoc/validation.adoc @@ -7,13 +7,13 @@ In order to tell Spring Data REST you want a particular `Validator` assigned to == Assigning Validators Manually -If you would rather not use the bean name prefix approach, you need to register an instance of your validator with the bean whose job it is to invoke validators after the correct event. In your configuration that implements `RepositoryRestConfigurer` or subclasses Spring Data REST's `RepositoryRestConfigurerAdapter`, override the `configureValidatingRepositoryEventListener` method and call `addValidator` on the `ValidatingRepositoryEventListener`, passing the event on which you want this validator to be triggered and an instance of the validator. The following example shows how to do so: +If you would rather not use the bean name prefix approach, you need to register an instance of your validator with the bean whose job it is to invoke validators after the correct event. In your configuration that implements `RepositoryRestConfigurer`, override the `configureValidatingRepositoryEventListener` method and call `addValidator` on the `ValidatingRepositoryEventListener`, passing the event on which you want this validator to be triggered and an instance of the validator. The following example shows how to do so: ==== [source,java] ---- @Override -protected void configureValidatingRepositoryEventListener(ValidatingRepositoryEventListener v) { +void configureValidatingRepositoryEventListener(ValidatingRepositoryEventListener v) { v.addValidator("beforeSave", new BeforeSaveValidator()); } ----