Skip to content

Commit 9bf6e1c

Browse files
committed
Merge branch '2.3.x'
Closes gh-23205
2 parents 3dfe11e + 116b247 commit 9bf6e1c

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
@@ -47,6 +47,7 @@
4747
import org.springframework.context.annotation.Bean;
4848
import org.springframework.context.annotation.Configuration;
4949
import org.springframework.context.support.AbstractApplicationContext;
50+
import org.springframework.core.Ordered;
5051
import org.springframework.core.env.PropertySource;
5152
import org.springframework.mock.web.MockServletContext;
5253
import org.springframework.web.context.WebApplicationContext;
@@ -133,6 +134,27 @@ void errorPageFilterRegistrationCanBeDisabled() {
133134
}
134135
}
135136

137+
@Test
138+
@SuppressWarnings("rawtypes")
139+
void errorPageFilterIsRegisteredWithNearHighestPrecedence() {
140+
WebServer webServer = new UndertowServletWebServerFactory(0).getWebServer((servletContext) -> {
141+
try (AbstractApplicationContext context = (AbstractApplicationContext) new WithErrorPageFilter()
142+
.createRootApplicationContext(servletContext)) {
143+
Map<String, FilterRegistrationBean> registrations = context
144+
.getBeansOfType(FilterRegistrationBean.class);
145+
assertThat(registrations).hasSize(1);
146+
FilterRegistrationBean errorPageFilterRegistration = registrations.get("errorPageFilterRegistration");
147+
assertThat(errorPageFilterRegistration.getOrder()).isEqualTo(Ordered.HIGHEST_PRECEDENCE + 1);
148+
}
149+
});
150+
try {
151+
webServer.start();
152+
}
153+
finally {
154+
webServer.stop();
155+
}
156+
}
157+
136158
@Test
137159
@SuppressWarnings("rawtypes")
138160
void errorPageFilterIsRegisteredForRequestAndAsyncDispatch() {

0 commit comments

Comments
 (0)