Skip to content

Commit 115ea87

Browse files
committed
Restore ordering of ErrorPageFilter lost in 49f8943
See gh-19471
1 parent c948c70 commit 115ea87

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/support/ErrorPageFilter.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.springframework.boot.web.server.ErrorPageRegistrar;
4444
import org.springframework.boot.web.server.ErrorPageRegistry;
4545
import org.springframework.core.Ordered;
46-
import org.springframework.core.annotation.Order;
4746
import org.springframework.util.ClassUtils;
4847
import org.springframework.web.filter.OncePerRequestFilter;
4948
import org.springframework.web.util.NestedServletException;
@@ -62,8 +61,7 @@
6261
* @author Andy Wilkinson
6362
* @since 2.0.0
6463
*/
65-
@Order(Ordered.HIGHEST_PRECEDENCE + 1)
66-
public class ErrorPageFilter implements Filter, ErrorPageRegistry {
64+
public class ErrorPageFilter implements Filter, ErrorPageRegistry, Ordered {
6765

6866
private static final Log logger = LogFactory.getLog(ErrorPageFilter.class);
6967

@@ -298,6 +296,11 @@ else if (errorPage.getStatus() != null) {
298296
public void destroy() {
299297
}
300298

299+
@Override
300+
public int getOrder() {
301+
return Ordered.HIGHEST_PRECEDENCE + 1;
302+
}
303+
301304
private static void addClassIfPresent(Collection<Class<?>> collection, String className) {
302305
try {
303306
collection.add(ClassUtils.forName(className, null));

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/support/ErrorPageFilterConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ ErrorPageFilter errorPageFilter() {
3838
@Bean
3939
FilterRegistrationBean<ErrorPageFilter> errorPageFilterRegistration(ErrorPageFilter filter) {
4040
FilterRegistrationBean<ErrorPageFilter> registration = new FilterRegistrationBean<>(filter);
41+
registration.setOrder(filter.getOrder());
4142
registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
4243
return registration;
4344
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/SpringBootServletInitializerTests.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.springframework.context.annotation.Bean;
4242
import org.springframework.context.annotation.Configuration;
4343
import org.springframework.context.support.AbstractApplicationContext;
44+
import org.springframework.core.Ordered;
4445
import org.springframework.core.env.PropertySource;
4546
import org.springframework.mock.web.MockServletContext;
4647
import org.springframework.web.context.WebApplicationContext;
@@ -120,6 +121,27 @@ void errorPageFilterRegistrationCanBeDisabled() {
120121
}
121122
}
122123

124+
@Test
125+
@SuppressWarnings("rawtypes")
126+
void errorPageFilterIsRegisteredWithNearHighestPrecedence() {
127+
WebServer webServer = new UndertowServletWebServerFactory(0).getWebServer((servletContext) -> {
128+
try (AbstractApplicationContext context = (AbstractApplicationContext) new WithErrorPageFilter()
129+
.createRootApplicationContext(servletContext)) {
130+
Map<String, FilterRegistrationBean> registrations = context
131+
.getBeansOfType(FilterRegistrationBean.class);
132+
assertThat(registrations).hasSize(1);
133+
FilterRegistrationBean errorPageFilterRegistration = registrations.get("errorPageFilterRegistration");
134+
assertThat(errorPageFilterRegistration.getOrder()).isEqualTo(Ordered.HIGHEST_PRECEDENCE + 1);
135+
}
136+
});
137+
try {
138+
webServer.start();
139+
}
140+
finally {
141+
webServer.stop();
142+
}
143+
}
144+
123145
@Test
124146
@SuppressWarnings("rawtypes")
125147
void errorPageFilterIsRegisteredForRequestAndAsyncDispatch() {

0 commit comments

Comments
 (0)