Spring MVC - Atom Feed View

[Last Updated: Oct 9, 2017]

This example shows how to use ROME Library to generate Atom feed in a Spring MVC application.


Additional Maven Dependency



Java Config class

public class MyWebConfig {

  public ViewResolver beanNameViewResolver() {
      BeanNameViewResolver resolver = new BeanNameViewResolver();
      return resolver;

  public ViewResolver jspViewResolver() {
      InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
      return viewResolver;

In above configuration, we are using BeanNameViewResolver for resolving the Atom view by it's bean name.

Implementing the View

Spring provides AbstractRssFeedView support class for generating ROME's RSS feed.

package com.logicbig.example;

import com.rometools.rome.feed.atom.Content;
import com.rometools.rome.feed.atom.Entry;
import com.rometools.rome.feed.atom.Feed;
import com.rometools.rome.feed.atom.Link;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.feed.AbstractAtomFeedView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class MyAtomFeedView extends AbstractAtomFeedView {

  protected void buildFeedMetadata(Map<String, Object> model, Feed feed,
                                   HttpServletRequest request) {

      FeedInfo feedInfo = (FeedInfo) model.get("feedInfo");

  protected List<Entry> buildFeedEntries(Map<String, Object> model,
                                         HttpServletRequest request,
                                         HttpServletResponse response) throws Exception {
      List<Entry> entries = new ArrayList<>();
      FeedInfo feedInfo = (FeedInfo) model.get("feedInfo");
      for (FeedEntry fe : feedInfo.getFeedEntries()) {
          Entry entry = new Entry();

          Link link = new Link();


          Content content = new Content();

      return entries;
public class FeedInfo {
  private String title;
  private String link;
  private String desc;
  private List<FeedEntry> feedEntries = new ArrayList<>();
public class FeedEntry {
  String title;
  String link;
  String content;
  Date date;

A Spring Controller

public class AtomFeedController {

  public String mainView() {
      return "main";

  public String handleForexRequest(Model model) {
      model.addAttribute("feedInfo", getFeedInfo());
      return "atomFeedView";

  private static FeedInfo getFeedInfo() {
      FeedInfo feedInfo = new FeedInfo();
      feedInfo.setTitle("Logicbig Tutorials");
      feedInfo.setDesc("Logicbig tutorials feed");

      List<FeedEntry> list = new ArrayList<>();
      list.add(createFeedEntry("Spring Framework", "spring-framework",
              "Spring Framework Tutorials", new Date()));
      list.add(createFeedEntry("Java EE", "java-ee-tutorial",
              "Java EE Tutorials", new Date()));
      list.add(createFeedEntry("Java Core", "/core-java-tutorial/",
              "Core Java Tutorials", new Date()));
      return feedInfo;

  private static FeedEntry createFeedEntry(String title, String uri,
                                           String content, Date date) {
      FeedEntry fe = new FeedEntry();
      fe.setLink("" + uri);
      return fe;


<h2>Spring Atom Feed Example</h2>
<a href="/atomFeed">Tutorials Feed</a>

To try examples, run embedded tomcat (configured in pom.xml of example project below):

mvn tomcat7:run-war


On clicking the 'Tutorials Feed' link:

Example Project

Dependencies and Technologies Used:

  • spring-webmvc 5.0.0.RELEASE: Spring Web MVC.
  • javax.servlet-api 3.1.0 Java Servlet API
  • rome 1.8.0: All Roads Lead to ROME. ROME is a set of Atom/RSS Java utilities that make it easy to work in Java with most syndication formats. Today it accepts all flavors of RSS (0.90, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0), Atom 0.3 and Atom 1.0 feeds. Rome includes a set of parsers and generators for the various flavors of feeds, as well as converters to convert from one format to another. The parsers can give you back Java objects that are either specific for the format you want to work with, or a generic normalized SyndFeed object that lets you work on with the data without bothering about the underlying format. [Description from rome-1.8.0.pom]
  • JDK 1.8
  • Maven 3.3.9

Spring Atom Feed View Example Select All Download
  • atom-feed-example
    • src
      • main
        • java
          • com
            • logicbig
              • example
          • webapp
            • WEB-INF
              • views

    See Also