Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import jakarta.servlet.DispatcherType;

import org.springframework.boot.web.error.ErrorPageRegistrarBeanPostProcessor;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -26,6 +27,7 @@
* Configuration for {@link ErrorPageFilter}.
*
* @author Andy Wilkinson
* @author Jay Choi
*/
@Configuration(proxyBeanMethods = false)
class ErrorPageFilterConfiguration {
Expand All @@ -43,4 +45,9 @@ FilterRegistrationBean<ErrorPageFilter> errorPageFilterRegistration(ErrorPageFil
return registration;
}

@Bean
static ErrorPageRegistrarBeanPostProcessor errorPageRegistrarBeanPostProcessor() {
return new ErrorPageRegistrarBeanPostProcessor();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.springframework.boot.context.logging.LoggingApplicationListener;
import org.springframework.boot.testsupport.system.CapturedOutput;
import org.springframework.boot.testsupport.system.OutputCaptureExtension;
import org.springframework.boot.web.error.ErrorPageRegistrarBeanPostProcessor;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
Expand All @@ -66,6 +67,7 @@
*
* @author Phillip Webb
* @author Andy Wilkinson
* @author Jay Choi
*/
@ExtendWith(OutputCaptureExtension.class)
class SpringBootServletInitializerTests {
Expand Down Expand Up @@ -135,6 +137,21 @@ void errorPageFilterRegistrationCanBeDisabled() {
}
}

@Test
void errorPageRegistrarBeanPostProcessorIsRegistered() {
ServletContext servletContext = mock(ServletContext.class);
given(servletContext.addFilter(any(), any(Filter.class))).willReturn(mock(Dynamic.class));
given(servletContext.getInitParameterNames()).willReturn(Collections.emptyEnumeration());
given(servletContext.getAttributeNames()).willReturn(Collections.emptyEnumeration());
try (AbstractApplicationContext context = (AbstractApplicationContext) new WithErrorPageFilter()
.createRootApplicationContext(servletContext)) {
assertThat(context).isNotNull();
Map<String, ErrorPageRegistrarBeanPostProcessor> beans = context
.getBeansOfType(ErrorPageRegistrarBeanPostProcessor.class);
assertThat(beans).hasSize(1);
}
}

@Test
@SuppressWarnings("rawtypes")
void errorPageFilterIsRegisteredWithNearHighestPrecedence() {
Expand Down
Loading