diff --git a/spring-web/src/main/java/org/springframework/web/HttpRequestHandler.java b/spring-web/src/main/java/org/springframework/web/HttpRequestHandler.java index 94b155c3c3..acd7f2b992 100644 --- a/spring-web/src/main/java/org/springframework/web/HttpRequestHandler.java +++ b/spring-web/src/main/java/org/springframework/web/HttpRequestHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,21 +49,12 @@ import jakarta.servlet.http.HttpServletResponse; * return value gives a clearer signature to callers other than the * DispatcherServlet, indicating that there will never be a view to render. * - *
Note that HttpRequestHandlers may optionally implement the - * {@link org.springframework.web.servlet.mvc.LastModified} interface, - * just like Controllers can, provided that they run within Spring's - * DispatcherServlet. However, this is usually not necessary, since - * HttpRequestHandlers typically only support POST requests to begin with. - * Alternatively, a handler may implement the "If-Modified-Since" HTTP - * header processing manually within its {@code handle} method. - * * @author Juergen Hoeller * @since 2.0 * @see org.springframework.web.context.support.HttpRequestHandlerServlet * @see org.springframework.web.servlet.DispatcherServlet * @see org.springframework.web.servlet.ModelAndView * @see org.springframework.web.servlet.mvc.Controller - * @see org.springframework.web.servlet.mvc.LastModified * @see org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter */ @FunctionalInterface diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java index 61aab3ec1d..b643c4fe17 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java @@ -49,14 +49,12 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.support.PropertiesLoaderUtils; import org.springframework.core.log.LogFormatUtils; -import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.server.RequestPath; import org.springframework.http.server.ServletServerHttpRequest; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.context.request.ServletWebRequest; import org.springframework.web.context.request.async.WebAsyncManager; import org.springframework.web.context.request.async.WebAsyncUtils; import org.springframework.web.multipart.MultipartException; @@ -933,7 +931,6 @@ public class DispatcherServlet extends FrameworkServlet { * @param response current HTTP response * @throws Exception in case of any kind of processing failure */ - @SuppressWarnings("deprecation") protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpServletRequest processedRequest = request; HandlerExecutionChain mappedHandler = null; @@ -956,24 +953,12 @@ public class DispatcherServlet extends FrameworkServlet { return; } - // Determine handler adapter for the current request. - HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler()); - - // Process last-modified header, if supported by the handler. - String method = request.getMethod(); - boolean isGet = HttpMethod.GET.matches(method); - if (isGet || HttpMethod.HEAD.matches(method)) { - long lastModified = ha.getLastModified(request, mappedHandler.getHandler()); - if (new ServletWebRequest(request, response).checkNotModified(lastModified) && isGet) { - return; - } - } - if (!mappedHandler.applyPreHandle(processedRequest, response)) { return; } - // Actually invoke the handler. + // Determine handler adapter and invoke the handler. + HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler()); mv = ha.handle(processedRequest, response, mappedHandler.getHandler()); if (asyncManager.isConcurrentHandlingStarted()) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerAdapter.java index 31b8176ce6..2978cc76e3 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -75,16 +75,4 @@ public interface HandlerAdapter { */ @Nullable ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception; - /** - * Same contract as for HttpServlet's {@code getLastModified} method. - * Can simply return -1 if there's no support in the handler class. - * @param request current HTTP request - * @param handler the handler to use - * @return the lastModified value for the given handler - * @deprecated as of 5.3.9 along with - * {@link org.springframework.web.servlet.mvc.LastModified}. - */ - @Deprecated - long getLastModified(HttpServletRequest request, Object handler); - } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/HandlerFunctionAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/HandlerFunctionAdapter.java index 5cd02df8c2..9725b9a01a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/HandlerFunctionAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/HandlerFunctionAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -171,12 +171,6 @@ public class HandlerFunctionAdapter implements HandlerAdapter, Ordered { } } - @Override - @SuppressWarnings("deprecation") - public long getLastModified(HttpServletRequest request, Object handler) { - return -1L; - } - private static class ServerRequestContext implements ServerResponse.Context { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleServletHandlerAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleServletHandlerAdapter.java index 522a8f934a..570e5f5c8a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleServletHandlerAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleServletHandlerAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,10 +67,4 @@ public class SimpleServletHandlerAdapter implements HandlerAdapter { return null; } - @Override - @SuppressWarnings("deprecation") - public long getLastModified(HttpServletRequest request, Object handler) { - return -1; - } - } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/HttpRequestHandlerAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/HttpRequestHandlerAdapter.java index a7217f9433..6ca9f883af 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/HttpRequestHandlerAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/HttpRequestHandlerAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,6 @@ import org.springframework.web.servlet.ModelAndView; /** * Adapter to use the plain {@link org.springframework.web.HttpRequestHandler} * interface with the generic {@link org.springframework.web.servlet.DispatcherServlet}. - * Supports handlers that implement the {@link LastModified} interface. * *
This is an SPI class, not used directly by application code. * @@ -52,13 +51,4 @@ public class HttpRequestHandlerAdapter implements HandlerAdapter { return null; } - @Override - @SuppressWarnings("deprecation") - public long getLastModified(HttpServletRequest request, Object handler) { - if (handler instanceof LastModified lastModified) { - return lastModified.getLastModified(request); - } - return -1L; - } - } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/LastModified.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/LastModified.java deleted file mode 100644 index a05c625a07..0000000000 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/LastModified.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2002-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.web.servlet.mvc; - -import jakarta.servlet.http.HttpServletRequest; - -/** - * Supports last-modified HTTP requests to facilitate content caching. - * Same contract as for the Servlet API's {@code getLastModified} method. - * - *
Delegated to by a {@link org.springframework.web.servlet.HandlerAdapter#getLastModified} - * implementation. By default, any Controller or HttpRequestHandler within Spring's - * default framework can implement this interface to enable last-modified checking. - * - *
Note: Alternative handler implementation approaches have different - * last-modified handling styles. For example, Spring 2.5's annotated controller - * approach (using {@code @RequestMapping}) provides last-modified support - * through the {@link org.springframework.web.context.request.WebRequest#checkNotModified} - * method, allowing for last-modified checking within the main handler method. - * - * @author Rod Johnson - * @author Juergen Hoeller - * @see jakarta.servlet.http.HttpServlet#getLastModified - * @see Controller - * @see SimpleControllerHandlerAdapter - * @see org.springframework.web.HttpRequestHandler - * @see HttpRequestHandlerAdapter - * @deprecated as of 5.3.9 in favor of using the {@code checkNotModified} methods - * in {@link org.springframework.web.context.request.WebRequest}, or from an - * annotated controller method, returning a - * {@link org.springframework.http.ResponseEntity} with an "ETag" and/or - * "Last-Modified" headers set. - */ -@Deprecated -public interface LastModified { - - /** - * Same contract as for HttpServlet's {@code getLastModified} method. - * Invoked before request processing. - *
The return value will be sent to the HTTP client as Last-Modified header, - * and compared with If-Modified-Since headers that the client sends back. - * The content will only get regenerated if there has been a modification. - * @param request current HTTP request - * @return the time the underlying resource was last modified, or -1 - * meaning that the content must always be regenerated - * @see org.springframework.web.servlet.HandlerAdapter#getLastModified - * @see jakarta.servlet.http.HttpServlet#getLastModified - */ - long getLastModified(HttpServletRequest request); - -} diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/SimpleControllerHandlerAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/SimpleControllerHandlerAdapter.java index f24ae82e9c..e578d617f6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/SimpleControllerHandlerAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/SimpleControllerHandlerAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,6 @@ import org.springframework.web.servlet.ModelAndView; /** * Adapter to use the plain {@link Controller} workflow interface with * the generic {@link org.springframework.web.servlet.DispatcherServlet}. - * Supports handlers that implement the {@link LastModified} interface. * *
This is an SPI class, not used directly by application code.
*
@@ -50,13 +49,4 @@ public class SimpleControllerHandlerAdapter implements HandlerAdapter {
return ((Controller) handler).handleRequest(request, response);
}
- @Override
- @SuppressWarnings("deprecation")
- public long getLastModified(HttpServletRequest request, Object handler) {
- if (handler instanceof LastModified lastModified) {
- return lastModified.getLastModified(request);
- }
- return -1L;
- }
-
}
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/AbstractHandlerMethodAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/AbstractHandlerMethodAdapter.java
index e29472f12f..013d83df0e 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/AbstractHandlerMethodAdapter.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/AbstractHandlerMethodAdapter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2023 the original author or authors.
+ * Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -99,24 +99,4 @@ public abstract class AbstractHandlerMethodAdapter extends WebContentGenerator i
protected abstract @Nullable ModelAndView handleInternal(HttpServletRequest request,
HttpServletResponse response, HandlerMethod handlerMethod) throws Exception;
- /**
- * This implementation expects the handler to be an {@link HandlerMethod}.
- */
- @Override
- @SuppressWarnings("deprecation")
- public final long getLastModified(HttpServletRequest request, Object handler) {
- return getLastModifiedInternal(request, (HandlerMethod) handler);
- }
-
- /**
- * Same contract as for {@link jakarta.servlet.http.HttpServlet#getLastModified(HttpServletRequest)}.
- * @param request current HTTP request
- * @param handlerMethod handler method to use
- * @return the lastModified value for the given handler
- * @deprecated as of 5.3.9 along with
- * {@link org.springframework.web.servlet.mvc.LastModified}.
- */
- @Deprecated
- protected abstract long getLastModifiedInternal(HttpServletRequest request, HandlerMethod handlerMethod);
-
}
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java
index 0787d197b2..d20d9559ff 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java
@@ -72,7 +72,6 @@ import org.springframework.web.bind.support.WebBindingInitializer;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.ServletWebRequest;
-import org.springframework.web.context.request.WebRequest;
import org.springframework.web.context.request.async.AsyncWebRequest;
import org.springframework.web.context.request.async.CallableProcessingInterceptor;
import org.springframework.web.context.request.async.DeferredResultProcessingInterceptor;
@@ -861,17 +860,6 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
return mav;
}
- /**
- * This implementation always returns -1. An {@code @RequestMapping} method can
- * calculate the lastModified value, call {@link WebRequest#checkNotModified(long)},
- * and return {@code null} if the result of that call is {@code true}.
- */
- @Override
- @SuppressWarnings("deprecation")
- protected long getLastModifiedInternal(HttpServletRequest request, HandlerMethod handlerMethod) {
- return -1;
- }
-
/**
* Return the {@link SessionAttributesHandler} instance for the given handler type
@@ -889,7 +877,6 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
* @since 4.2
* @see #createInvocableHandlerMethod(HandlerMethod)
*/
- @SuppressWarnings("deprecation")
protected @Nullable ModelAndView invokeHandlerMethod(HttpServletRequest request,
HttpServletResponse response, HandlerMethod handlerMethod) throws Exception {
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java
index 4f5a3f7907..54c27be4ea 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2024 the original author or authors.
+ * Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -334,24 +334,6 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport {
applyCacheControl(response, cControl);
}
-
- /**
- * Check and prepare the given request and response according to the settings
- * of this generator.
- * @see #checkRequest(HttpServletRequest)
- * @see #applyCacheSeconds(HttpServletResponse, int)
- * @deprecated as of 4.2, since the {@code lastModified} flag is effectively ignored,
- * with a must-revalidate header only generated if explicitly configured
- */
- @Deprecated
- protected final void checkAndPrepare(
- HttpServletRequest request, HttpServletResponse response, int cacheSeconds, boolean lastModified)
- throws ServletException {
-
- checkRequest(request);
- applyCacheSeconds(response, cacheSeconds);
- }
-
private Collection