Use bean name for servlet and filter registrations if name is not set

If the name is set, it is used. If not, the bean name is used. If that's
not set, the convention based name is taken.

Registration failures now throw an IllegalStateException instead of
being logged. DynamicRegistrationBean.setIgnoreRegistrationFailure
can be used to restore the old behavior.

See gh-33911
This commit is contained in:
Moritz Halbritter
2023-01-19 17:00:53 +01:00
parent e6351b57ca
commit a4e7a8bae0
10 changed files with 165 additions and 26 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 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.
@@ -144,6 +144,7 @@ public class JerseyAutoConfiguration implements ServletContextAware {
addInitParameters(registration);
registration.setName(getServletRegistrationName());
registration.setLoadOnStartup(this.jersey.getServlet().getLoadOnStartup());
registration.setIgnoreRegistrationFailure(true);
return registration;
}

View File

@@ -501,7 +501,10 @@ class ServletWebServerFactoryAutoConfigurationTests {
@Bean(name = DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME)
ServletRegistrationBean<DispatcherServlet> dispatcherRegistration(DispatcherServlet dispatcherServlet) {
return new ServletRegistrationBean<>(dispatcherServlet, "/app/*");
ServletRegistrationBean<DispatcherServlet> registration = new ServletRegistrationBean<>(dispatcherServlet,
"/app/*");
registration.setName(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
return registration;
}
}