Skip to content

Commit 5f6df35

Browse files
committed
Remove deprecated LastModified APIs
See gh-33809
1 parent 65df309 commit 5f6df35

15 files changed

+14
-307
lines changed

spring-web/src/main/java/org/springframework/web/HttpRequestHandler.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,21 +49,12 @@
4949
* return value gives a clearer signature to callers other than the
5050
* DispatcherServlet, indicating that there will never be a view to render.
5151
*
52-
* <p>Note that HttpRequestHandlers may optionally implement the
53-
* {@link org.springframework.web.servlet.mvc.LastModified} interface,
54-
* just like Controllers can, <i>provided that they run within Spring's
55-
* DispatcherServlet</i>. However, this is usually not necessary, since
56-
* HttpRequestHandlers typically only support POST requests to begin with.
57-
* Alternatively, a handler may implement the "If-Modified-Since" HTTP
58-
* header processing manually within its {@code handle} method.
59-
*
6052
* @author Juergen Hoeller
6153
* @since 2.0
6254
* @see org.springframework.web.context.support.HttpRequestHandlerServlet
6355
* @see org.springframework.web.servlet.DispatcherServlet
6456
* @see org.springframework.web.servlet.ModelAndView
6557
* @see org.springframework.web.servlet.mvc.Controller
66-
* @see org.springframework.web.servlet.mvc.LastModified
6758
* @see org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter
6859
*/
6960
@FunctionalInterface

spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java

+2-17
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,12 @@
4949
import org.springframework.core.io.ClassPathResource;
5050
import org.springframework.core.io.support.PropertiesLoaderUtils;
5151
import org.springframework.core.log.LogFormatUtils;
52-
import org.springframework.http.HttpMethod;
5352
import org.springframework.http.MediaType;
5453
import org.springframework.http.server.RequestPath;
5554
import org.springframework.http.server.ServletServerHttpRequest;
5655
import org.springframework.util.ClassUtils;
5756
import org.springframework.util.StringUtils;
5857
import org.springframework.web.context.WebApplicationContext;
59-
import org.springframework.web.context.request.ServletWebRequest;
6058
import org.springframework.web.context.request.async.WebAsyncManager;
6159
import org.springframework.web.context.request.async.WebAsyncUtils;
6260
import org.springframework.web.multipart.MultipartException;
@@ -933,7 +931,6 @@ else if (isEnableLoggingRequestDetails()) {
933931
* @param response current HTTP response
934932
* @throws Exception in case of any kind of processing failure
935933
*/
936-
@SuppressWarnings("deprecation")
937934
protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception {
938935
HttpServletRequest processedRequest = request;
939936
HandlerExecutionChain mappedHandler = null;
@@ -956,24 +953,12 @@ protected void doDispatch(HttpServletRequest request, HttpServletResponse respon
956953
return;
957954
}
958955

959-
// Determine handler adapter for the current request.
960-
HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler());
961-
962-
// Process last-modified header, if supported by the handler.
963-
String method = request.getMethod();
964-
boolean isGet = HttpMethod.GET.matches(method);
965-
if (isGet || HttpMethod.HEAD.matches(method)) {
966-
long lastModified = ha.getLastModified(request, mappedHandler.getHandler());
967-
if (new ServletWebRequest(request, response).checkNotModified(lastModified) && isGet) {
968-
return;
969-
}
970-
}
971-
972956
if (!mappedHandler.applyPreHandle(processedRequest, response)) {
973957
return;
974958
}
975959

976-
// Actually invoke the handler.
960+
// Determine handler adapter and invoke the handler.
961+
HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler());
977962
mv = ha.handle(processedRequest, response, mappedHandler.getHandler());
978963

979964
if (asyncManager.isConcurrentHandlingStarted()) {

spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerAdapter.java

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -75,16 +75,4 @@ public interface HandlerAdapter {
7575
*/
7676
@Nullable ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception;
7777

78-
/**
79-
* Same contract as for HttpServlet's {@code getLastModified} method.
80-
* Can simply return -1 if there's no support in the handler class.
81-
* @param request current HTTP request
82-
* @param handler the handler to use
83-
* @return the lastModified value for the given handler
84-
* @deprecated as of 5.3.9 along with
85-
* {@link org.springframework.web.servlet.mvc.LastModified}.
86-
*/
87-
@Deprecated
88-
long getLastModified(HttpServletRequest request, Object handler);
89-
9078
}

spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/HandlerFunctionAdapter.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -171,12 +171,6 @@ else if (result == null) {
171171
}
172172
}
173173

174-
@Override
175-
@SuppressWarnings("deprecation")
176-
public long getLastModified(HttpServletRequest request, Object handler) {
177-
return -1L;
178-
}
179-
180174

181175
private static class ServerRequestContext implements ServerResponse.Context {
182176

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleServletHandlerAdapter.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -67,10 +67,4 @@ public boolean supports(Object handler) {
6767
return null;
6868
}
6969

70-
@Override
71-
@SuppressWarnings("deprecation")
72-
public long getLastModified(HttpServletRequest request, Object handler) {
73-
return -1;
74-
}
75-
7670
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/HttpRequestHandlerAdapter.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,7 +27,6 @@
2727
/**
2828
* Adapter to use the plain {@link org.springframework.web.HttpRequestHandler}
2929
* interface with the generic {@link org.springframework.web.servlet.DispatcherServlet}.
30-
* Supports handlers that implement the {@link LastModified} interface.
3130
*
3231
* <p>This is an SPI class, not used directly by application code.
3332
*
@@ -52,13 +51,4 @@ public boolean supports(Object handler) {
5251
return null;
5352
}
5453

55-
@Override
56-
@SuppressWarnings("deprecation")
57-
public long getLastModified(HttpServletRequest request, Object handler) {
58-
if (handler instanceof LastModified lastModified) {
59-
return lastModified.getLastModified(request);
60-
}
61-
return -1L;
62-
}
63-
6454
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/LastModified.java

-65
This file was deleted.

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/SimpleControllerHandlerAdapter.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,7 +26,6 @@
2626
/**
2727
* Adapter to use the plain {@link Controller} workflow interface with
2828
* the generic {@link org.springframework.web.servlet.DispatcherServlet}.
29-
* Supports handlers that implement the {@link LastModified} interface.
3029
*
3130
* <p>This is an SPI class, not used directly by application code.
3231
*
@@ -50,13 +49,4 @@ public boolean supports(Object handler) {
5049
return ((Controller) handler).handleRequest(request, response);
5150
}
5251

53-
@Override
54-
@SuppressWarnings("deprecation")
55-
public long getLastModified(HttpServletRequest request, Object handler) {
56-
if (handler instanceof LastModified lastModified) {
57-
return lastModified.getLastModified(request);
58-
}
59-
return -1L;
60-
}
61-
6252
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/AbstractHandlerMethodAdapter.java

+1-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -99,24 +99,4 @@ public final boolean supports(Object handler) {
9999
protected abstract @Nullable ModelAndView handleInternal(HttpServletRequest request,
100100
HttpServletResponse response, HandlerMethod handlerMethod) throws Exception;
101101

102-
/**
103-
* This implementation expects the handler to be an {@link HandlerMethod}.
104-
*/
105-
@Override
106-
@SuppressWarnings("deprecation")
107-
public final long getLastModified(HttpServletRequest request, Object handler) {
108-
return getLastModifiedInternal(request, (HandlerMethod) handler);
109-
}
110-
111-
/**
112-
* Same contract as for {@link jakarta.servlet.http.HttpServlet#getLastModified(HttpServletRequest)}.
113-
* @param request current HTTP request
114-
* @param handlerMethod handler method to use
115-
* @return the lastModified value for the given handler
116-
* @deprecated as of 5.3.9 along with
117-
* {@link org.springframework.web.servlet.mvc.LastModified}.
118-
*/
119-
@Deprecated
120-
protected abstract long getLastModifiedInternal(HttpServletRequest request, HandlerMethod handlerMethod);
121-
122102
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java

-13
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
import org.springframework.web.bind.support.WebDataBinderFactory;
7373
import org.springframework.web.context.request.NativeWebRequest;
7474
import org.springframework.web.context.request.ServletWebRequest;
75-
import org.springframework.web.context.request.WebRequest;
7675
import org.springframework.web.context.request.async.AsyncWebRequest;
7776
import org.springframework.web.context.request.async.CallableProcessingInterceptor;
7877
import org.springframework.web.context.request.async.DeferredResultProcessingInterceptor;
@@ -861,17 +860,6 @@ protected boolean supportsInternal(HandlerMethod handlerMethod) {
861860
return mav;
862861
}
863862

864-
/**
865-
* This implementation always returns -1. An {@code @RequestMapping} method can
866-
* calculate the lastModified value, call {@link WebRequest#checkNotModified(long)},
867-
* and return {@code null} if the result of that call is {@code true}.
868-
*/
869-
@Override
870-
@SuppressWarnings("deprecation")
871-
protected long getLastModifiedInternal(HttpServletRequest request, HandlerMethod handlerMethod) {
872-
return -1;
873-
}
874-
875863

876864
/**
877865
* Return the {@link SessionAttributesHandler} instance for the given handler type
@@ -889,7 +877,6 @@ private SessionAttributesHandler getSessionAttributesHandler(HandlerMethod handl
889877
* @since 4.2
890878
* @see #createInvocableHandlerMethod(HandlerMethod)
891879
*/
892-
@SuppressWarnings("deprecation")
893880
protected @Nullable ModelAndView invokeHandlerMethod(HttpServletRequest request,
894881
HttpServletResponse response, HandlerMethod handlerMethod) throws Exception {
895882

spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java

+1-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -334,24 +334,6 @@ else if (cacheSeconds == 0) {
334334
applyCacheControl(response, cControl);
335335
}
336336

337-
338-
/**
339-
* Check and prepare the given request and response according to the settings
340-
* of this generator.
341-
* @see #checkRequest(HttpServletRequest)
342-
* @see #applyCacheSeconds(HttpServletResponse, int)
343-
* @deprecated as of 4.2, since the {@code lastModified} flag is effectively ignored,
344-
* with a must-revalidate header only generated if explicitly configured
345-
*/
346-
@Deprecated
347-
protected final void checkAndPrepare(
348-
HttpServletRequest request, HttpServletResponse response, int cacheSeconds, boolean lastModified)
349-
throws ServletException {
350-
351-
checkRequest(request);
352-
applyCacheSeconds(response, cacheSeconds);
353-
}
354-
355337
private Collection<String> getVaryRequestHeadersToAdd(HttpServletResponse response, String[] varyByRequestHeaders) {
356338
if (!response.containsHeader(HttpHeaders.VARY)) {
357339
return Arrays.asList(varyByRequestHeaders);

spring-webmvc/src/test/java/org/springframework/web/servlet/ComplexWebApplicationContext.java

-12
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,6 @@ public ModelAndView handle(HttpServletRequest request, HttpServletResponse respo
261261
((MyHandler) delegate).doSomething(request);
262262
return null;
263263
}
264-
265-
@Deprecated
266-
@Override
267-
public long getLastModified(HttpServletRequest request, Object delegate) {
268-
return ((MyHandler) delegate).lastModified();
269-
}
270264
}
271265

272266

@@ -282,12 +276,6 @@ public ModelAndView handle(HttpServletRequest request, HttpServletResponse respo
282276
throws IOException, ServletException {
283277
throw new ServletException("dummy");
284278
}
285-
286-
@Deprecated
287-
@Override
288-
public long getLastModified(HttpServletRequest request, Object delegate) {
289-
return -1;
290-
}
291279
}
292280

293281

0 commit comments

Comments
 (0)