3131import reactor .netty .http .server .HttpServer ;
3232
3333import org .springframework .boot .WebApplicationType ;
34- import org .springframework .boot .autoconfigure .web .ErrorProperties ;
35- import org .springframework .boot .autoconfigure .web .WebProperties .Resources ;
3634import org .springframework .boot .webflux .autoconfigure .error .DefaultErrorWebExceptionHandler ;
37- import org .springframework .boot .webflux .error .DefaultErrorAttributes ;
38- import org .springframework .boot .webflux .error .ErrorAttributes ;
3935import org .springframework .cloud .function .context .FunctionCatalog ;
4036import org .springframework .cloud .function .context .FunctionProperties ;
4137import org .springframework .cloud .function .context .FunctionalSpringApplication ;
5652import org .springframework .core .env .Environment ;
5753import org .springframework .core .env .MapPropertySource ;
5854import org .springframework .http .ResponseEntity ;
59- import org .springframework .http .codec .ServerCodecConfigurer ;
6055import org .springframework .http .server .reactive .HttpHandler ;
6156import org .springframework .http .server .reactive .ReactorHttpHandlerAdapter ;
6257import org .springframework .util .Assert ;
@@ -92,7 +87,7 @@ public class FunctionEndpointInitializer implements ApplicationContextInitialize
9287
9388 @ Override
9489 public void initialize (GenericApplicationContext context ) {
95- if (errorAttributes && webflux && ContextFunctionCatalogInitializer .enabled
90+ if (webflux && ContextFunctionCatalogInitializer .enabled
9691 && context .getEnvironment ().getProperty (FunctionalSpringApplication .SPRING_WEB_APPLICATION_TYPE ,
9792 WebApplicationType .class , WebApplicationType .REACTIVE ) == WebApplicationType .REACTIVE
9893 && context .getEnvironment ().getProperty ("spring.functional.enabled" , Boolean .class , false )) {
@@ -102,7 +97,9 @@ public void initialize(GenericApplicationContext context) {
10297 }
10398
10499 private void registerWebFluxAutoConfiguration (GenericApplicationContext context ) {
105- context .registerBean (DefaultErrorWebExceptionHandler .class , () -> errorHandler (context ));
100+ if (errorAttributes ) {
101+ context .registerBean (DefaultErrorWebExceptionHandler .class , () -> ErrorHandlerRegistrar .errorHandler (context ));
102+ }
106103 context .registerBean (WebHttpHandlerBuilder .WEB_HANDLER_BEAN_NAME , HttpWebHandlerAdapter .class ,
107104 () -> httpHandler (context ));
108105 context .addApplicationListener (new ServerListener (context ));
@@ -122,19 +119,7 @@ private HttpWebHandlerAdapter httpHandler(GenericApplicationContext context) {
122119 .codecs (config -> config .registerDefaults (true )).build ());
123120 }
124121
125- private DefaultErrorWebExceptionHandler errorHandler (GenericApplicationContext context ) {
126- context .registerBean (ErrorAttributes .class , () -> new DefaultErrorAttributes ());
127- context .registerBean (ErrorProperties .class , () -> new ErrorProperties ());
128-
129- context .registerBean (Resources .class , () -> new Resources ());
130- DefaultErrorWebExceptionHandler handler = new DefaultErrorWebExceptionHandler (
131- context .getBeansOfType (ErrorAttributes .class ).values ().iterator ().next (), context .getBean (Resources .class ),
132- context .getBean (ErrorProperties .class ), context );
133- ServerCodecConfigurer codecs = ServerCodecConfigurer .create ();
134- handler .setMessageWriters (codecs .getWriters ());
135- handler .setMessageReaders (codecs .getReaders ());
136- return handler ;
137- }
122+
138123
139124 private static final class RouterFunctionRegister {
140125
0 commit comments