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 47
47
import org .springframework .context .annotation .Bean ;
48
48
import org .springframework .context .annotation .Configuration ;
49
49
import org .springframework .context .support .AbstractApplicationContext ;
50
+ import org .springframework .core .Ordered ;
50
51
import org .springframework .core .env .PropertySource ;
51
52
import org .springframework .mock .web .MockServletContext ;
52
53
import org .springframework .web .context .WebApplicationContext ;
@@ -133,6 +134,27 @@ void errorPageFilterRegistrationCanBeDisabled() {
133
134
}
134
135
}
135
136
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
+
136
158
@ Test
137
159
@ SuppressWarnings ("rawtypes" )
138
160
void errorPageFilterIsRegisteredForRequestAndAsyncDispatch () {
You can’t perform that action at this time.
0 commit comments