Note
A huge thanks to @rajadilipkolli for his efforts in updating this repository to the newest Spring Boot v4.
This is a sandbox project for demonstrating Reactive Streams support in the Spring framework and the broader Spring ecosystem.
I've also maintained a series of repositories related to Reactive Streams and the latest Spring 5:
- Spring RSocket Sample
- Spring Kotlin Coroutines Example
- Spring Kotlin DSL/Spring Fu Sample
- Spring WebMvc Functional Example
- Angular and Spring Reactive Example
- Spring R2dbc Example (updates for Spring 5.3, Spring Data R2dbc 1.2, and Spring Boot 2.4)
The source codes have been updated to Spring 7 / Spring Boot v4.
- The Spring Boot 3.x based codes are available in a compressed archive and tagged with boot-3.
- The Spring Boot 2.x based codes are available in a compressed archive and tagged with v1.0.
Read online: https://hantsy.github.io/spring-reactive-sample/
The following table lists all sample codes available in this repository.
| Name | Description |
|---|---|
| vanilla | Basic spring-webflux features with a main class to start the application |
| vanilla-reactor-netty2 | Same as vanilla, but uses Reactor Netty 2.x as the runtime |
| vanilla-jetty | Same as vanilla, but uses Jetty as the runtime |
| vanilla-tomcat | Same as vanilla, but uses Tomcat as the runtime |
| vanilla-undertow | Same as vanilla, but uses Undertow as the runtime |
| java8 | Java 8 CompletableFuture and @Async example |
| java9 | Same as vanilla, with Java 9 Flow API support (see SPR-16052) |
| rxjava3 | Same as vanilla, but uses RxJava 3 instead of Reactor (since Spring 5.3.0) |
| smallrye-mutiny | Same as vanilla, but uses SmallRye Mutiny instead of Reactor (since Spring 5.3.10) |
| rxjava3 | Same as vanilla, but use Rxjava3 instead of Reactor, since Spring 5.3.0 |
| smallrye-mutiny | Same as vanilla, but use SmallRye Mutiny instead of Reactor, since Spring 5.3.10 |
| war | Replaces the manual bootstrap with Spring ApplicationInitializer, can be packaged as a war file for external servlet containers |
| routes | Uses RouterFunction instead of @Controller |
| register-bean | Programmatic bean registration in ApplicationContext at bootstrap |
| data-elasticsearch | Spring Data ElasticSearch Reactive example |
| data-neo4j | Spring Data Neo4j reactive example |
| data-mongo | Spring Data Mongo Reactive example |
| data-mongo-pageable | Spring Data Mongo Reactive example with pagination support |
| data-mongo-transaction | Spring Data Mongo Reactive example with Transaction support |
| data-redis | Spring Data Redis Reactive example |
| data-redis-message | Spring Data Redis Reactive example with ReactiveRedisMessageListenerContainer |
| data-cassandra | Spring Data Cassandra Reactive example |
| data-couchbase | Spring Data Couchbase Reactive example |
| security | Adds Spring Security Reactive support to vanilla |
| security-form | Same as security, with login form example |
| security-user-properties | Same as security, but stores users in users.properties |
| security-method | Replaces URI-based configuration with method-level constraints |
| security-data-mongo | Based on data-mongo and security, replaces hard-coded users with Mongo-driven store |
| multipart | Multipart request handling and file uploading |
| multipart-data-mongo | Multipart and file uploading, data stored in Mongo via Spring Data Mongo Reactive GridFsTemplate |
| mvc-thymeleaf | Traditional web application using Thymeleaf as template engine |
| mvc-mustache | Traditional web application using Mustache as template engine |
| mvc-freemarker | Traditional web application using Freemarker as template engine |
| sse | Server Send Event example |
| websocket | WebSocket example |
| websocket-reactor-netty2 | WebSocket example with Reactor Netty 2 |
| web-filter | WebFilter example |
| groovy | Written in Groovy |
| groovy-dsl | Groovy DSL bean definition example |
| client | WebClient example for calling backend reactive APIs |
| client-jetty | WebClient with Jetty Reactive HttpClient |
| client-reactor-netty2 | WebClient with Reactor Netty 2.x HttpClient |
| client-jdk11-httpclient | WebClient with JDK 11 HttpClient |
| client-apache-httpclient5 | WebClient with Apache HttpClient 5 |
| cache | Cache Async/Reactive support with in-memory ConcurrentHashMap |
| cache-caffeine | Cache Async/Reactive support with Caffeine |
| cache-redis | Cache Async/Reactive support with Redis |
| event | Application Event Reactive example |
| kotlin | Written in Kotlin |
| kotlin-co | Written in Kotlin Coroutines |
| kotlin-routes | Kotlin functional approach to declare beans and bootstrap programmatically |
| kotlin-dsl | Kotlin DSL bean definition example |
| schedule | Spring Schedule Reactive example |
| session | Spring Session example |
| session-header | Spring Session WebSessionIdResolver example |
| session-data-redis | Spring Data Redis based ReactiveSessionRepository example |
| session-data-mongo | Spring Data Mongo based ReactiveSessionRepository example |
| exception-handler | Exception Handler example |
| integration | Spring Integration example |
| integration-dsl | Spring Integration Java 8 DSL example |
| restdocs | Spring RestDocs example |
| Name | Description |
|---|---|
| boot-start | Spring Boot example with 3 Maven profiles to switch between Jetty, Tomcat, and Undertow |
| boot-start-routes | Simple RouterFunction example |
| boot-mvc-thymeleaf | Same as mvc-thymeleaf, based on Spring Boot |
| boot-mvc-mustache | Same as mvc-mustache, based on Spring Boot |
| boot-mvc-freemarker | Same as mvc-freemarker, based on Spring Boot |
| boot-groovy | Written in Groovy |
| boot-kotlin | Written in Kotlin |
| boot-kotlin-co | Written in Kotlin Coroutines |
| boot-kotlin-dsl | Kotlin-specific BeanDefinitionDSL and RouterFunctionDsl example |
| boot-kotlin-co-dsl | Kotlin-specific BeanDefinitionDSL and CoRouterFunctionDsl example |
| boot-redis | Example using ReactiveRedisConnection and RouterFunction |
| boot-data-redis | Spring Data Redis example |
| boot-data-neo4j | Spring Data Neo4j example (Spring Boot 2.4) |
| boot-neo4j | Spring Data Neo4j using ReactiveNeo4jOperations (Spring Boot 2.4) |
| boot-neo4j-cypher | Spring Data Neo4j using ReactiveNeo4jClient (Spring Boot 2.4) |
| boot-data-cassandra | Spring Data Cassandra example |
| boot-data-couchbase | Spring Data Couchbase example |
| boot-data-elasticsearch | Spring Data ElasticSearch example |
| boot-data-mongo | Spring Data Mongo example (Repository, Auditing, testcontainers) |
| boot-data-mongo-querydsl | Spring Data Mongo example with QueryDSL support |
| boot-data-mongo-gridfs | Spring Data Mongo example with GridFS support |
| boot-data-mongo-tailable | Spring Data Mongo tailable document example |
| boot-exception-handler | Global Exception Handler example |
| boot-pulsar | Spring for Pulsar Reactive example |
Some example codes are becoming deprecated over time, e.g., the SDN Rx project, which was maintained by the Neo4j team, has been discontinued. It is highly recommended to migrate to the official Spring Data Neo4j.
Spring Data R2dbc 1.2 introduced many breaking changes, so I created another Spring R2dbc Sample repository to introduce the new features.
Spring removed support of RxJava/RxJava2, and other projects, such as Spring Data, will remove RxJava/RxJava2 support soon.
| name | description |
|---|---|
| data-r2dbc | Spring Data R2dbc Example. (Deprecated, go to hantsy/spring-r2dbc-sample to update yourself) |
| data-r2dbc-postgresql | Spring Data R2dbc Example, but use PostgreSQL instead(Deprecated) |
| boot-r2dbc | Spring Data R2dbc example using DatabaseClient(Deprecated) |
| boot-data-r2dbc | Spring Data R2dbc example(Deprecated) |
| boot-data-r2dbc-auditing | @EnableR2dbcAuditing example(Deprecated) |
| boot-data-r2dbc-postgresql | Same as boot-data-r2dbc, but use PostgresSQL instead(Deprecated) |
| boot-data-r2dbc-mysql | Same as boot-data-r2dbc, but use MySQL instead(Deprecated) |
| boot-data-r2dbc-mssql | Same as boot-data-r2dbc, but use MS SQL instead(Deprecated) |
| boot-neo4j-rx | SDN Rx Example but use ReactiveNeo4jClient(Deprecated) |
| boot-neo4j-rx-cypher | SDN Rx Example using Cypher queries(Deprecated) |
| boot-data-neo4j-rx | SDN Rx Example(Deprecated) |
| rxjava | Same as vanilla, but use Rxjava instead of Reactor |
| rxjava-jdbc | Accessing database with rxjava-jdbc. NOTE: rxjava-jdbc is a wrapper of blocking Jdbc APIs |
| rxjava2 | Same as vanilla, but use Rxjava2 instead of Reactor |
| rxjava2-jdbc | Accessing database with rxjava2-jdbc. NOTE: rxjava2-jdbc is a wrapper of blocking Jdbc APIs |
-
Reactive Streams, official Reactive Streams website
-
Understanding Reactive types, Spring.IO
-
The WebFlux framework, Spring Framework Reference Documentation
-
Reactor Core 3.0 becomes a unified Reactive Foundation on Java 8, Spring.IO
-
Reactive Spring, Spring.IO
-
Three parts of Notes on Reactive Programming by Dave Syer:
-
Kotlin extensions for MongoOperations and ReactiveMongoOperations
Special thanks to JetBrains for supporting an open-source license.
