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.
This commit is contained in:
Greg L. Turnquist
2021-03-15 16:30:09 -05:00
committed by Mark Paluch
parent 51206fbffd
commit 015335d9ef
3 changed files with 10 additions and 10 deletions

View File

@@ -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")

View File

@@ -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");
}
}

View File

@@ -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());
}
----