http://nixmash.com/post/rss-feeds-with-spring-boot

****************************************

We added a RSS Subscription to NixMash Spring Posts in like 10 minutes. Okay, probably longer than that but it was really quick.

Here's our feed XML, the Real Deal in RSS feeds. See it live here.

The FeedView

Creating RSS Feeds in Spring is all about its AbstractFeedView classes. There's anAbstractAtomFeedView,AbstractRssFeedViewand other supporting classes.

In (1) you'll see we're extending Spring'sAbstractRssFeedViewclass. Also notice on the first line we're explicitly naming the Component. This is important as we'll be passing it by name to the Controller. Next we create our Channel Header and populate it withApplicationSettingsfrom an external properties file (2). We retrieve our Post List, stream it, modify it with ourcreateItem(post)method and return our list of Feed Items (3). Slick!

Spring uses the Rome Subscription Tools v1.5 or higher, so we need to add theRomeToolsdependency inbuild.gradle.

compile 'com.rometools:rome:1.6.1'

The Controller

Now that we've created our SpringRssPostViewall we have to do is add it to our model. Notice we're adding the Bean name, and Spring takes over in parsing and populating the feed from the Component. That's pretty cool.

Configuring the FeedView Resolver

You may see other posts that mention the need to configure the RssFeed View Resolver, since we're configuring a view resolver. Something like…

@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
registry.enableContentNegotiation(new RssPostFeedView());
}

…in aWebMvcConfigurerclass. This is no longer needed, which is very wonderful.

The Test

Here's a quick test to confirm we're delivering media with content typeapplication/rss-xml.

In Summary

To sum up, to create an RSS or Atom feed with Spring you

  1. Create a FeedView component that extends a Spring Abstract FeedView superclass
  2. Pass that component by name from your Controller method model to the client

Source Code Notes for this Post

All source code discussed in this post can be found in my NixMash Spring GitHub repo and viewed online here.

Posted 七月 14, 2016 09:33 上午 EDT
 

RSS Feeds with Spring Boot的更多相关文章

  1. Spring Boot 之 RESRful API 权限控制

    摘要: 原创出处:www.bysocket.com 泥瓦匠BYSocket 希望转载,保留摘要,谢谢! “简单,踏实~ 读书写字放屁” 一.为何用RESTful API 1.1 RESTful是什么? ...

  2. Spring boot 内存优化

    转自:https://dzone.com/articles/spring-boot-memory-performance It has sometimes been suggested that Sp ...

  3. Spring Boot Memory Performance

    The Performance Zone is brought to you in partnership with New Relic. Quickly learn how to use Docke ...

  4. 通过docker-composer启动容器nginx,并完成spring.boot的web站点端口转发

    前面已经讲过2篇基于docker的mysql.redis容器编排并启动.这次将练习下nginx的docker方式的部署,以及通过nginx去代理宿主主机上的Web服务应该怎么配 PS:(这里由于ngi ...

  5. spring cloud:搭建基于consul的服务提供者集群(spring cloud hoxton sr8 / spring boot 2.3.4)

    一,搭建基于consul的服务提供者集群 1,consul集群,共3个实例: 2, 服务提供者集群:共2个实例: 3,服务消费者:一个实例即可 4,consul集群的搭建,请参考: https://w ...

  6. 玩转spring boot——快速开始

    开发环境: IED环境:Eclipse JDK版本:1.8 maven版本:3.3.9 一.创建一个spring boot的mcv web应用程序 打开Eclipse,新建Maven项目 选择quic ...

  7. 【微框架】之一:从零开始,轻松搞定SpringCloud微框架系列--开山篇(spring boot 小demo)

    Spring顶级框架有众多,那么接下的篇幅,我将重点讲解SpringCloud微框架的实现 Spring 顶级项目,包含众多,我们重点学习一下,SpringCloud项目以及SpringBoot项目 ...

  8. 玩转spring boot——开篇

    很久没写博客了,而这一转眼就是7年.这段时间并不是我没学习东西,而是园友们的技术提高的非常快,这反而让我不知道该写些什么.我做程序已经有十几年之久了,可以说是彻彻底底的“程序老炮”,至于技术怎么样?我 ...

  9. 玩转spring boot——结合redis

    一.准备工作 下载redis的windows版zip包:https://github.com/MSOpenTech/redis/releases 运行redis-server.exe程序 出现黑色窗口 ...

随机推荐

  1. uniq命令 (转)

    uniq命令可以去除排序过的文件中的重复行,因此uniq经常和sort合用.也就是说,为了使uniq起作用,所有的重复行必须是相邻的. uniq语法 [root@www ~]# uniq [-icu] ...

  2. maven 创建web项目的标准目录结构

      maven 创建web项目的标准目录结构 CreateTime--2018年4月18日21:05:37 Author:Marydon 1.标准目录介绍(开发目录) 2.在eclipse下,目录展示 ...

  3. ORA-27090 故障一例

    近期的alert日志中碰到了ORA-27090的错误信息.其错误提示为Unable to reserve kernel resources for asynchronous disk I/O.依据这个 ...

  4. Javascript模块化编程:require.js的用法

    摘自:http://blog.jobbole.com/30046/ 这个系列的第一部分和第二部分,介绍了Javascript模块原型和理论概念,今天介绍如何将它们用于实战. 我采用的是一个非常流行的库 ...

  5. PHP:微信小程序调用【统一下单】【微信支付】【支付回调】API;XML转Array,Array转XML方法(通用)

    1.微信公众号.微信小程序开发过程中,第三方服务器与微信服务器数据交互,需要进行数据转换,必须用到这两个函数: 分别是xml_to_array.array_to_xml ; /** * 输出xml字符 ...

  6. hdu--DFS

    DFS Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  7. Web 前端性能优化相关内容解析[转]

    Web 前端性能优化相关内容,来源于<Google官方网页载入速度检测工具PageSpeed Insights 使用教程>一文中PageSpeed Insights 的相关说明.大家可以对 ...

  8. 【jQuery】网上看到一个不错的登陆界面

    预览截图如下: Html部分代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...

  9. -no-xrender will disable the qtwebkit

    -no-xrender will disable the qtwebkit         apt-get install libxrender-dev 来自为知笔记(Wiz)

  10. Linux内核中锁机制之完成量、互斥量

    在上一篇博文中笔者分析了关于信号量.读写信号量的使用及源码实现,接下来本篇博文将讨论有关完成量和互斥量的使用和一些经典问题. 八.完成量 下面讨论完成量的内容,首先需明确完成量表示为一个执行单元需要等 ...