Streaming Data with Spring Boot

Swathi Prasad
The Startup
Published in
4 min readJun 30, 2019

--

Streaming data is a radical new approach to sending data to web browsers which provides for dramatically faster page load times.

Spring and Spring Boot

Quite often, we need to allow users to download files in web applications. When the data is too large, it becomes quite a challenge to provide a good user experience.

Spring offers support for asynchronous request processing via StreamingResponseBody. In this approach, application can write data directly to the response OutputStream without holding up the Servlet container thread. There are a few other methods in Spring to handle asynchronous request processing.

In this article, we are going to look at an example to download files using StreamingResponseBody. In this approach, data is processed and written in chunks to the OutputStream.

Setting Up Spring Boot Project

Create a sample Spring Boot application. Here is my sample project structure. I have created the project manually, but you could also create using Spring Intializer.

Project Structure

Let us add some basic dependencies to Maven POM.

<?xml version="1.0" encoding="UTF-8"?>
<project

--

--

Swathi Prasad
The Startup

Software architect and developer living in Germany. Sharing my opinion and what I learn.