Skip to content

Commit 1fcb5ec

Browse files
committed
Merge pull request #9340 from vpavic:improve-webmvc-registrations
* pr/9340: Replace `WebMvcRegistrationsAdapter` with default methods
2 parents 3b7c7c2 + 639641f commit 1fcb5ec

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcRegistrations.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,26 @@ public interface WebMvcRegistrations {
4040
* processed by the MVC configuration.
4141
* @return the custom {@link RequestMappingHandlerMapping} instance
4242
*/
43-
RequestMappingHandlerMapping getRequestMappingHandlerMapping();
43+
default RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
44+
return null;
45+
}
4446

4547
/**
4648
* Return the custom {@link RequestMappingHandlerAdapter} that should be used and
4749
* processed by the MVC configuration.
4850
* @return the custom {@link RequestMappingHandlerAdapter} instance
4951
*/
50-
RequestMappingHandlerAdapter getRequestMappingHandlerAdapter();
52+
default RequestMappingHandlerAdapter getRequestMappingHandlerAdapter() {
53+
return null;
54+
}
5155

5256
/**
5357
* Return the custom {@link ExceptionHandlerExceptionResolver} that should be used and
5458
* processed by the MVC configuration.
5559
* @return the custom {@link ExceptionHandlerExceptionResolver} instance
5660
*/
57-
ExceptionHandlerExceptionResolver getExceptionHandlerExceptionResolver();
61+
default ExceptionHandlerExceptionResolver getExceptionHandlerExceptionResolver() {
62+
return null;
63+
}
5864

5965
}

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcRegistrationsAdapter.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,16 @@
1616

1717
package org.springframework.boot.autoconfigure.web.servlet;
1818

19-
import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver;
20-
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
21-
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
22-
2319
/**
2420
* An implementation of {@link WebMvcRegistrations} with empty methods allowing
2521
* sub-classes to override only the methods they're interested in.
2622
*
2723
* @author Brian Clozel
2824
* @since 1.4.0
25+
* @deprecated as of 2.0.0 {@link WebMvcRegistrations} has default methods (made possible
26+
* by a Java 8 baseline) and can be implemented directly without the need for this adapter
2927
*/
28+
@Deprecated
3029
public class WebMvcRegistrationsAdapter implements WebMvcRegistrations {
3130

32-
@Override
33-
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
34-
return null;
35-
}
36-
37-
@Override
38-
public RequestMappingHandlerAdapter getRequestMappingHandlerAdapter() {
39-
return null;
40-
}
41-
42-
@Override
43-
public ExceptionHandlerExceptionResolver getExceptionHandlerExceptionResolver() {
44-
return null;
45-
}
46-
4731
}

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,8 @@ public HttpPutFormContentFilter customHttpPutFormContentFilter() {
899899
static class CustomRequestMappingHandlerMapping {
900900

901901
@Bean
902-
public WebMvcRegistrationsAdapter webMvcRegistrationsHandlerMapping() {
903-
return new WebMvcRegistrationsAdapter() {
902+
public WebMvcRegistrations webMvcRegistrationsHandlerMapping() {
903+
return new WebMvcRegistrations() {
904904

905905
@Override
906906
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
@@ -921,8 +921,8 @@ private static class MyRequestMappingHandlerMapping
921921
static class CustomRequestMappingHandlerAdapter {
922922

923923
@Bean
924-
public WebMvcRegistrationsAdapter webMvcRegistrationsHandlerAdapter() {
925-
return new WebMvcRegistrationsAdapter() {
924+
public WebMvcRegistrations webMvcRegistrationsHandlerAdapter() {
925+
return new WebMvcRegistrations() {
926926

927927
@Override
928928
public RequestMappingHandlerAdapter getRequestMappingHandlerAdapter() {

0 commit comments

Comments
 (0)