下面列出了org.springframework.http.server.reactive.ReactorHttpHandlerAdapter#org.springframework.web.reactive.DispatcherHandler 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected HttpHandler createHttpHandler() {
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
wac.register(TestConfiguration.class);
wac.refresh();
return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(wac)).build();
}
@Override
protected HttpHandler createHttpHandler() {
this.wac = new AnnotationConfigApplicationContext();
this.wac.register(TestConfiguration.class);
this.wac.refresh();
DispatcherHandler webHandler = new DispatcherHandler();
webHandler.setApplicationContext(this.wac);
return WebHttpHandlerBuilder.webHandler(webHandler).build();
}
@Override
protected HttpHandler createHttpHandler() {
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
wac.register(WebConfig.class);
wac.refresh();
return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(wac))
.exceptionHandler(new ResponseStatusExceptionHandler())
.build();
}
@Override
protected HttpHandler createHttpHandler() {
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
wac.register(TestConfiguration.class);
wac.refresh();
return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(wac)).build();
}
@Override
protected HttpHandler createHttpHandler() {
this.wac = new AnnotationConfigApplicationContext();
this.wac.register(TestConfiguration.class);
this.wac.refresh();
return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(this.wac)).build();
}
@Override
protected HttpHandler createHttpHandler() {
this.wac = new AnnotationConfigApplicationContext();
this.wac.register(TestConfiguration.class);
this.wac.refresh();
return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(this.wac)).build();
}
@Override
protected HttpHandler createHttpHandler() {
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
wac.register(TestConfiguration.class);
wac.refresh();
return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(wac)).build();
}
@Override
protected HttpHandler createHttpHandler() {
this.wac = new AnnotationConfigApplicationContext();
this.wac.register(TestConfiguration.class);
this.wac.refresh();
DispatcherHandler webHandler = new DispatcherHandler();
webHandler.setApplicationContext(this.wac);
return WebHttpHandlerBuilder.webHandler(webHandler).build();
}
@Override
protected HttpHandler createHttpHandler() {
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
wac.register(WebConfig.class);
wac.refresh();
return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(wac))
.exceptionHandler(new ResponseStatusExceptionHandler())
.build();
}
@Override
protected HttpHandler createHttpHandler() {
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
wac.register(TestConfiguration.class);
wac.refresh();
return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(wac)).build();
}
@Override
protected HttpHandler createHttpHandler() {
this.wac = new AnnotationConfigApplicationContext();
this.wac.register(TestConfiguration.class);
this.wac.refresh();
return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(this.wac)).build();
}
@Override
protected HttpHandler createHttpHandler() {
this.wac = new AnnotationConfigApplicationContext();
this.wac.register(TestConfiguration.class);
this.wac.refresh();
return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(this.wac)).build();
}
@Override
public void initialize(GenericApplicationContext context) {
context.registerBean("webServerFactoryCustomizerBeanPostProcessor", WebServerFactoryCustomizerBeanPostProcessor.class, WebServerFactoryCustomizerBeanPostProcessor::new);
context.registerBean(ReactiveWebServerFactoryCustomizer.class, () -> new ReactiveWebServerFactoryCustomizer(this.serverProperties));
context.registerBean(ConfigurableReactiveWebServerFactory.class, () -> serverFactory);
//noinspection deprecation
context.registerBean(ErrorAttributes.class, () -> new DefaultErrorAttributes(serverProperties.getError().isIncludeException()));
context.registerBean(ErrorWebExceptionHandler.class, () -> {
ErrorWebFluxAutoConfiguration errorConfiguration = new ErrorWebFluxAutoConfiguration(this.serverProperties);
return errorConfiguration.errorWebExceptionHandler(context.getBean(ErrorAttributes.class), this.resourceProperties, context.getBeanProvider(ViewResolver.class), context.getBean(SERVER_CODEC_CONFIGURER_BEAN_NAME, ServerCodecConfigurer.class), context);
});
context.registerBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class, () -> new EnableWebFluxConfigurationWrapper(context, webFluxProperties));
context.registerBean(LOCALE_CONTEXT_RESOLVER_BEAN_NAME, LocaleContextResolver.class, () -> context.getBean(EnableWebFluxConfigurationWrapper.class).localeContextResolver());
context.registerBean("responseStatusExceptionHandler", WebExceptionHandler.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).responseStatusExceptionHandler());
context.registerBean(RouterFunctionMapping.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).routerFunctionMapping(context.getBean(SERVER_CODEC_CONFIGURER_BEAN_NAME, ServerCodecConfigurer.class)));
context.registerBean(SERVER_CODEC_CONFIGURER_BEAN_NAME, ServerCodecConfigurer.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).serverCodecConfigurer());
context.registerBean("webFluxAdapterRegistry", ReactiveAdapterRegistry.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).webFluxAdapterRegistry());
context.registerBean("handlerFunctionAdapter", HandlerFunctionAdapter.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).handlerFunctionAdapter());
context.registerBean("webFluxContentTypeResolver", RequestedContentTypeResolver.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).webFluxContentTypeResolver());
context.registerBean("webFluxConversionService", FormattingConversionService.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).webFluxConversionService());
context.registerBean("serverResponseResultHandler", ServerResponseResultHandler.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).serverResponseResultHandler(context.getBean(SERVER_CODEC_CONFIGURER_BEAN_NAME, ServerCodecConfigurer.class)));
context.registerBean("simpleHandlerAdapter", SimpleHandlerAdapter.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).simpleHandlerAdapter());
context.registerBean("viewResolutionResultHandler", ViewResolutionResultHandler.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).viewResolutionResultHandler(context.getBean("webFluxAdapterRegistry", ReactiveAdapterRegistry.class), context.getBean("webFluxContentTypeResolver", RequestedContentTypeResolver.class)));
context.registerBean("webFluxValidator", Validator.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).webFluxValidator());
context.registerBean(HttpHandler.class, () -> applicationContext(context).build());
context.registerBean(WEB_HANDLER_BEAN_NAME, DispatcherHandler.class, (Supplier<DispatcherHandler>) DispatcherHandler::new);
context.registerBean(WebFluxConfig.class, () -> new WebFluxConfig(resourceProperties, webFluxProperties, context, context.getBeanProvider(HandlerMethodArgumentResolver.class), context.getBeanProvider(CodecCustomizer.class),
context.getBeanProvider(ResourceHandlerRegistrationCustomizer.class), context.getBeanProvider(ViewResolver.class)));
}
@Bean
public NettyContext nettyContext(ApplicationContext context) {
HttpHandler handler = DispatcherHandler.toHttpHandler(context);
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("8095"));
return httpServer.newHandler(adapter).block();
}
@Bean
public NettyContext nettyContext(ApplicationContext context) {
HttpHandler handler = DispatcherHandler.toHttpHandler(context);
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("8908"));
return httpServer.newHandler(adapter).block();
}
@Bean
public NettyContext nettyContext(ApplicationContext context) {
HttpHandler handler = DispatcherHandler.toHttpHandler(context);
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("8901"));
return httpServer.newHandler(adapter).block();
}
@Bean
public NettyContext nettyContext(ApplicationContext context) {
HttpHandler handler = DispatcherHandler.toHttpHandler(context);
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("9007"));
return httpServer.newHandler(adapter).block();
}
@Bean
public NettyContext nettyContext(ApplicationContext context) {
HttpHandler handler = DispatcherHandler.toHttpHandler(context);
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("9006"));
return httpServer.newHandler(adapter).block();
}
@Bean
public NettyContext nettyContext(ApplicationContext context) {
HttpHandler handler = DispatcherHandler.toHttpHandler(context);
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("8901"));
return httpServer.newHandler(adapter).block();
}
@Bean
public NettyContext nettyContext(ApplicationContext context) {
HttpHandler handler = DispatcherHandler.toHttpHandler(context);
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("8909"));
return httpServer.newHandler(adapter).block();
}
@Bean
public NettyContext nettyContext(ApplicationContext context) {
HttpHandler handler = DispatcherHandler.toHttpHandler(context);
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("8125"));
return httpServer.newHandler(adapter).block();
}
@Bean
public NettyContext nettyContext(ApplicationContext context) {
HttpHandler handler = DispatcherHandler.toHttpHandler(context);
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("9008"));
return httpServer.newHandler(adapter).block();
}
@Bean
public NettyContext nettyContext(ApplicationContext context) {
HttpHandler handler = DispatcherHandler.toHttpHandler(context);
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("8901"));
return httpServer.newHandler(adapter).block();
}
@Bean
public NettyContext nettyContext(ApplicationContext context) {
HttpHandler handler = DispatcherHandler.toHttpHandler(context);
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("8095"));
return httpServer.newHandler(adapter).block();
}
@Bean
public NettyContext nettyContext(ApplicationContext context) {
HttpHandler handler = DispatcherHandler.toHttpHandler(context);
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("9008"));
return httpServer.newHandler(adapter).block();
}
@Bean
public NettyContext nettyContext(ApplicationContext context) {
HttpHandler handler = DispatcherHandler.toHttpHandler(context);
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("8908"));
return httpServer.newHandler(adapter).block();
}
private static ApplicationContext applicationContext(WebFilter... webFilters) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
for(WebFilter filter : webFilters) {
context.registerBean(WebFilter.class, () -> filter);
}
context.registerBean("webHandler", DispatcherHandler.class, () -> new DispatcherHandler());
context.registerBean(HandlerMapping.class, () -> RouterFunctions.toHandlerMapping(request -> Mono.just(r -> ServerResponse.ok().build())));
context.registerBean(HandlerAdapter.class, () -> new HandlerFunctionAdapter());
context.registerBean(HandlerResultHandler.class, () -> new ServerResponseResultHandler());
context.refresh();
return context;
}
@Bean
public NettyContext nettyContext(ApplicationContext context) {
HttpHandler handler = DispatcherHandler.toHttpHandler(context);
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create("localhost", port);
return httpServer.newHandler(adapter).block();
}
@Bean
@ConditionalOnBean(ReactiveResilience4JCircuitBreakerFactory.class)
public SpringCloudCircuitBreakerResilience4JFilterFactory springCloudCircuitBreakerResilience4JFilterFactory(
ReactiveResilience4JCircuitBreakerFactory reactiveCircuitBreakerFactory,
ObjectProvider<DispatcherHandler> dispatcherHandler) {
return new SpringCloudCircuitBreakerResilience4JFilterFactory(
reactiveCircuitBreakerFactory, dispatcherHandler);
}
public SpringCloudCircuitBreakerFilterFactory(
ReactiveCircuitBreakerFactory reactiveCircuitBreakerFactory,
ObjectProvider<DispatcherHandler> dispatcherHandlerProvider) {
super(Config.class);
this.reactiveCircuitBreakerFactory = reactiveCircuitBreakerFactory;
this.dispatcherHandlerProvider = dispatcherHandlerProvider;
}