CORS Headers for a Spring Boot Kotlin WebFlux Reactor projectby Christoph Dähne on 03.07.2017
If enabled, CORS (Cross-origin resource sharing) allows a web page to use resources from another domain which are usually restricted. When you develop a web application on your local machine you often need CORS even if the production web page does not.
The CORS enabling code samples in this Blog post are written in Kotlin. Since May 2017 Kotlin is an official Android language. The JVM–based language compiles into Java byte code and is interoperable with Java libraries. I can only recommend to give it a try and enjoy leaving auto-generated boilerplate behind. The language reminds me of Groovy and Scala though it is more than a mix of those two.
Spring Boot is an application we use to build Java web–applications. The following CORS Component is a WebFilter thus executed for any HTTP request before going to the path–specific code. The @Component annotation makes the WebFilter visible to Spring Boot so it is wired–up during application startup.
The WebFlux starter for Spring Boot leverages non-blocking request processing and provides a functional API which works smoothly with Kotlin. If you want to get deep into Spring Boot WebFlux Kotlin Application check out this full–size project on GitHub.