As you know there are thousands of news websites where you can read news in HTML format with your web browser. These sites are often colorful and overloaded with images. This is great as long as they’re accessed through an unlimited and fast internet connection. But it’s different when you’re using devices with limited connectivity or if you are situated in an area with a poor connection. In this cases a more efficient technology is desirable.

Therefore most of these sites provide their content as RSS (an abbreviation for Rich Site Summary) feed. RSS is a technology providing information in a standardized (XML) way. There are few formats in various versions specified, but the most common and current ones are ‘RSS 2.0’ and ‘Atom 1.0’.
Most modern web browsers can read RSS feeds. Additionally there are hundreds of apps for each operating system and flavor of user.

This blog post demonstrates how to provide your own RSS Atom 1.0 feed with Spring Boot, Spring REST and the ROME library.

The open source ROME library is released under the terms of the Apache 2.0 license. It provides functionality to read, write and convert data between XML (feed) and human readable contents.

Before starting please make sure that you have installed a current Java JDK and an IDE (if desired). Now let’s start implementing the RSS feed.

1. Generate Spring Boot project

Navigate with your web browser to and generate a Gradle Project using Spring Boot 1.4.0 and the “Web” dependency.

Spring Initializr - Spring Boot 1.4.0, Gradle, Web

Extract the zip archive and import it to your IDE.

2. Add ROME library dependency to gradle build file

Open the build.gradle file in the root directory of the extracted folder. Add the ROME dependency (compile group: ‘com.rometools’, name: ‘rome’, version: ‘1.7.0’) above the existing ones:

3. Create REST controller

Open the file demo/src/main/java/com/example/ and modify the source code as shown below:

The following table explains what’s happening in the previously shown class line by line.

Line Meaning
20 Register class as REST controller in the spring context
21 Mark application as Spring Boot application so that it’s auto configured at startup
25 Main method to bootstrap the application. Starts the tomcat server and registers the current REST controller to it.
28 Register the following method to be called when the root resource is requested (e.g. http://localhost:8080/)
29 Define that the response is plain text
31 Create RSS feed
32 Set feed type to Atom Version 1.0
34-38 Create (news) feed entry, set title, create content and set text to publish
40-41 Add content to entry and entry to feed
43 Export feed as String and return it as REST call response

4. Build and run

Finally build the Gradle application on the command line using the command:
./gradlew clean build

Navigate on the command line to the directory build/libs and execute the following command to start the application:
java -jar demo-0.0.1-SNAPSHOT.jar

Open your favorite RSS reader or web browser and navigate to http://<hostname>:8080/. As you can see there is the RSS feed.

RSS Feed

That’s it!

You’ve created your first simple RSS feed using Spring Boot, Spring REST and the ROME library. If you’re looking for some future inspiration how to enrich your feed, please have a look on the list of tutorials and articels.

Leave a Comment

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.