File tree Expand file tree Collapse file tree 3 files changed +29
-3
lines changed
spring-boot-project/spring-boot/src
main/java/org/springframework/boot/web/servlet/support
test/java/org/springframework/boot/web/servlet/support Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 43
43
import org .springframework .boot .web .server .ErrorPageRegistrar ;
44
44
import org .springframework .boot .web .server .ErrorPageRegistry ;
45
45
import org .springframework .core .Ordered ;
46
- import org .springframework .core .annotation .Order ;
47
46
import org .springframework .util .ClassUtils ;
48
47
import org .springframework .web .filter .OncePerRequestFilter ;
49
48
import org .springframework .web .util .NestedServletException ;
62
61
* @author Andy Wilkinson
63
62
* @since 2.0.0
64
63
*/
65
- @ Order (Ordered .HIGHEST_PRECEDENCE + 1 )
66
- public class ErrorPageFilter implements Filter , ErrorPageRegistry {
64
+ public class ErrorPageFilter implements Filter , ErrorPageRegistry , Ordered {
67
65
68
66
private static final Log logger = LogFactory .getLog (ErrorPageFilter .class );
69
67
@@ -298,6 +296,11 @@ else if (errorPage.getStatus() != null) {
298
296
public void destroy () {
299
297
}
300
298
299
+ @ Override
300
+ public int getOrder () {
301
+ return Ordered .HIGHEST_PRECEDENCE + 1 ;
302
+ }
303
+
301
304
private static void addClassIfPresent (Collection <Class <?>> collection , String className ) {
302
305
try {
303
306
collection .add (ClassUtils .forName (className , null ));
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ ErrorPageFilter errorPageFilter() {
38
38
@ Bean
39
39
FilterRegistrationBean <ErrorPageFilter > errorPageFilterRegistration (ErrorPageFilter filter ) {
40
40
FilterRegistrationBean <ErrorPageFilter > registration = new FilterRegistrationBean <>(filter );
41
+ registration .setOrder (filter .getOrder ());
41
42
registration .setDispatcherTypes (DispatcherType .REQUEST , DispatcherType .ASYNC );
42
43
return registration ;
43
44
}
Original file line number Diff line number Diff line change 41
41
import org .springframework .context .annotation .Bean ;
42
42
import org .springframework .context .annotation .Configuration ;
43
43
import org .springframework .context .support .AbstractApplicationContext ;
44
+ import org .springframework .core .Ordered ;
44
45
import org .springframework .core .env .PropertySource ;
45
46
import org .springframework .mock .web .MockServletContext ;
46
47
import org .springframework .web .context .WebApplicationContext ;
@@ -120,6 +121,27 @@ void errorPageFilterRegistrationCanBeDisabled() {
120
121
}
121
122
}
122
123
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
+
123
145
@ Test
124
146
@ SuppressWarnings ("rawtypes" )
125
147
void errorPageFilterIsRegisteredForRequestAndAsyncDispatch () {
You can’t perform that action at this time.
0 commit comments