Giter Club home page Giter Club logo

spring-boot-web-reactive's Introduction

Spring Boot Web Reactive Starter

This experimental project provides a simple way to try the new Web Reactive support in Spring Framework 5.0.

Quickstart

Go to start.spring.io, set the Spring Boot version to 2.0.0(SNAPSHOT) and add the "Reactive Web" starter.

From there you can take a look at spring-boot-sample-web-reactive in this repository to see examples of reactive @Controllers and the reactive WebClient in use.

Server Runtime

By default this Boot Starter uses embedded Tomcat as the default server runtime.

Switching the server is easy. Simply exclude the Tomcat starter and add the dependency you want as shown here with Reactor Netty:

<dependency>
	<groupId>org.springframework.boot.experimental</groupId>
	<artifactId>spring-boot-starter-web-reactive</artifactId>
	<exclusions>
		<exclusion>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupId>io.projectreactor.ipc</groupId>
	<artifactId>reactor-netty</artifactId>
</dependency>

An example of the same in Gradle and a switch to RxNetty:

compile('org.springframework.boot.experimental:spring-boot-starter-web-reactive') {
	exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
compile "io.reactivex:rxnetty-common"
compile "io.reactivex:rxnetty-http"
compile "io.reactivex:rxjava-reactive-streams"

Below are the supported server runtimes. For the exact dependencies check out the sample project build:

  • Reactor Netty
  • Tomcat
  • Jetty
  • RxNetty
  • Undertow

Annotation-based or Functional API

As described in the "Reactive Web Applications" Spring Framework 5.0 reference documentation, the Web Reactive framework comes in 2 flavors :

  • Annotation-based with @Controller and the other annotations supported also with Spring MVC
  • Functional, Java 8 lambda style routing and handling

Support of the annotation-based variant works like Spring MVC supports: @Controller beans are taking automatically in account. But we also introduced support for the functional variant. Such support is triggered by RouterFunction beans which can be annotated with any @Component style annotation (@Controller being one of the possible choices if you put your RouterFunction and HandlerFunctionin the same class). You can see an example of such Spring Boot functional web application with this functional-web-playground java-based sample application or this MiXiT Kotlin-based project.

WebClient Dependencies

Spring Framework 5 also provides a reactive WebClient. For now the only supported HTTP client is Reactor Netty. Other HTTP clients such as Jetty and RxNetty will be added in the next milestone.

Resources

The Spring team has published a few blog posts on the subject:

Supported configuration keys

Configuration class Supported properties Notes
ReactiveServerProperties server.port, server.address
ResourceProperties spring.resources.*
WebReactiveProperties spring.reactive.static-path-pattern
ReactorCoreProperties spring.reactor.stacktrace-mode.enabled Defaults to true if devtools is on the classpath, should be set to false in production for best performance.

Known issues

This starter doesn't work with plain @SpringBootTests (i.e. with a WebEnvironment.MOCK, which is the default):

Caused by: java.lang.IllegalArgumentException: Unable to call initializer.
Object of class [org.springframework.boot.context.embedded.ReactiveWebApplicationContext]
must be an instance of interface org.springframework.web.context.ConfigurableWebApplicationContext

Web integration tests @SpringBootTests are working properly, for example @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT).

FAQ

I've found an issue, I have a question - where should I report it?

  • You can report issues in this Github project or on https://jira.spring.io if this is a Spring Framework issue
  • You can ask questions in Github issues as well or join the Gitter chat

Will this be available in Spring Boot? When?

Yes! Check out the Spring Boot milestones and especially the dedicated issue.

Is Spring Boot required to run Spring Web Reactive?

It certainly makes things easier, but it's not mandatory. For manual bootstrapping, please [read the reference documentation] (http://docs.spring.io/spring-framework/docs/5.0.0.BUILD-SNAPSHOT/spring-framework-reference/html/web-reactive.html#web-reactive-getting-started-manual).

spring-boot-web-reactive's People

Contributors

bclozel avatar snicoll avatar rstoyanchev avatar sdeleuze avatar danielfernandez avatar olegdokuka avatar spencergibb avatar geoand avatar

Watchers

James Cloos avatar Dejan Stojadinović avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.