Skip to content

ServletListenerRegistrationBean and Servlet 3.0 #31160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pmv opened this issue May 24, 2022 · 1 comment
Closed

ServletListenerRegistrationBean and Servlet 3.0 #31160

pmv opened this issue May 24, 2022 · 1 comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@pmv
Copy link

pmv commented May 24, 2022

Let me start by saying I realize spring 5+ / spring-boot 2+ are documented as requiring Java EE 7 / Servlet 3.1+. With that said, in practice we have been successfully running on a servlet 3.0 environment until this change: #24879 (our use case is similar to this comment: #24879 (comment))

I would like to open a PR with a change like this:

diff --git "a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletListenerRegistrationBean.java" "b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletListenerRegistrationBean.java"
index f8f7896334..c970f949be 100644
--- "a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletListenerRegistrationBean.java"
+++ "b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletListenerRegistrationBean.java"
@@ -57,6 +57,9 @@ import org.springframework.util.ClassUtils;
  */
 public class ServletListenerRegistrationBean<T extends EventListener> extends RegistrationBean {
 
+	private static boolean servlet31 = ClassUtils.isPresent("javax.servlet.http.HttpSessionIdListener",
+			ServletListenerRegistrationBean.class.getClassLoader());
+
 	private static final Set<Class<?>> SUPPORTED_TYPES;
 
 	static {
@@ -65,9 +68,11 @@ public class ServletListenerRegistrationBean<T extends EventListener> extends Re
 		types.add(ServletRequestListener.class);
 		types.add(ServletRequestAttributeListener.class);
 		types.add(HttpSessionAttributeListener.class);
-		types.add(HttpSessionIdListener.class);
 		types.add(HttpSessionListener.class);
 		types.add(ServletContextListener.class);
+		if (servlet31) {
+			types.add(HttpSessionIdListener.class);
+		}
 		SUPPORTED_TYPES = Collections.unmodifiableSet(types);
 	}

(If I open a PR I'll include a test also).

However, before taking the time, I would like to understand if such a change has a chance of being merged. Having this change available in future spring-boot 2.6.x and 2.7.x versions would be useful for us (and perhaps others also), but I understand if this is something you would not accept due to documented requirements.

Please let me know your thoughts, and thanks in advance for your time.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 24, 2022
@wilkinsona
Copy link
Member

wilkinsona commented May 24, 2022

Sorry, but this isn't a change that we will make. We've required Servlet 3.1 since 2.0 and Framework has required it since 5.0. Even if we made the change that you are suggesting, you'd still be using an unsupported arrangement as Framework would still require Servlet 3.1.

@wilkinsona wilkinsona added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

3 participants