You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The above loads default Spring Web Reactive config (1), then creates a
181
262
`DispatcherHandler`, the main class driving request processing (2), and adapts
182
263
it to `HttpHandler`, the lowest level Spring abstraction for reactive HTTP request handling.
183
-
An `HttpHandler` can then be installed in each supported runtime:
264
+
265
+
For the **functional programming model**, bootstrap code start with:
266
+
[source,java,indent=0]
267
+
[subs="verbatim,quotes"]
268
+
----
269
+
ApplicationContext context = new AnnotationConfigApplicationContext(); // (1)
270
+
context.registerBean(FooBean.class, () -> new FooBeanImpl()); // (2)
271
+
context.registerBean(BarBean.class); // (3)
272
+
HttpHandler handler = WebHttpHandlerBuilder
273
+
.webHandler(RouterFunctions.toHttpHandler(...))
274
+
.applicationContext(context)
275
+
.build(); // (4)
276
+
----
277
+
278
+
The above creates an `AnnotationConfigApplicationContext` instance (1) that can take advantage
279
+
of the new functional bean registration API (2) to register beans using a Java 8 `Supplier`
280
+
or just by specifying its class (3). The `HttpHandler` is created using `WebHttpHandlerBuilder` (4).
281
+
282
+
**Common to both** annotation and functional flavors, an `HttpHandler` can then be installed in each supported runtime:
184
283
185
284
[source,java,indent=0]
186
285
[subs="verbatim,quotes"]
@@ -191,8 +290,10 @@ HttpServlet servlet = new ServletHttpHandlerAdapter(handler);
191
290
192
291
// Reactor Netty
193
292
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
194
-
HttpServer server = HttpServer.create(host, port);
195
-
server.startAndAwait(adapter);
293
+
HttpServer.create(host, port)
294
+
.newHandler(adapter)
295
+
.doOnNext(c -> System.out.println("Server listening on " + c.address())).block()
296
+
.onClose().block();
196
297
197
298
// RxNetty
198
299
RxNettyHttpHandlerAdapter adapter = new RxNettyHttpHandlerAdapter(handler);
@@ -213,12 +314,17 @@ and it registers for you the `ServletHttpHandlerAdapter` shown above.
213
314
Only implement one method to point to your Spring Java configuration classes.
214
315
====
215
316
317
+
[[web-reactive-getting-started-examples]]
318
+
=== Examples
216
319
320
+
You will find code examples useful to build your own Spring Web Reactive application in these projects:
217
321
218
-
219
-
[[web-reactive-getting-started-M1]]
220
-
=== Extent of Support in 5.0 M1
221
-
222
-
For M1 the Spring Web Reactive module focuses on REST scenarios for both
223
-
client and server. Basic HTML rendering with Freemarker is also supported but
224
-
limited to rendering but not form submissions.
322
+
* https://github.com/bclozel/spring-boot-web-reactive[Spring Boot Web Reactive Starter]: sources of the reactive starter available at http://start.spring.io
323
+
* https://github.com/poutsma/web-function-sample[Functional programming model sample]
324
+
* https://github.com/sdeleuze/spring-reactive-playground[Spring Reactive Playground]: plaground for most Spring Web Reactive features
325
+
* https://github.com/reactor/projectreactor.io/tree/spring-functional[Reactor website]: the `spring-functional` branch is a Spring Web Reactive functional web application
326
+
* https://github.com/bclozel/spring-reactive-university[Spring Reactive University]: live-coded project from https://www.youtube.com/watch?v=Cj4foJzPF80[this Devoxx BE 2106 university talk]
* https://github.com/mix-it/mixit/[Mix-it 2017 website]: Kotlin + Reactive + Functional web and bean registration API application
329
+
* https://github.com/simonbasle/reactor-by-example[Reactor by example]: code snippets coming from this https://www.infoq.com/articles/reactor-by-example[InfoQ article]
330
+
* https://github.com/spring-projects/spring-framework/tree/master/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation[Spring Web Reactive integration tests]: various features tested with Reactor https://projectreactor.io/docs/test/release/api/index.html?reactor/test/StepVerifier.html[`StepVerifier`]
0 commit comments