RSS Feeds with Spring Boot
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
- Create a FeedView component that extends a Spring Abstract FeedView superclass
- 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.
RSS Feeds with Spring Boot的更多相关文章
- Spring Boot 之 RESRful API 权限控制
摘要: 原创出处:www.bysocket.com 泥瓦匠BYSocket 希望转载,保留摘要,谢谢! “简单,踏实~ 读书写字放屁” 一.为何用RESTful API 1.1 RESTful是什么? ...
- Spring boot 内存优化
转自:https://dzone.com/articles/spring-boot-memory-performance It has sometimes been suggested that Sp ...
- Spring Boot Memory Performance
The Performance Zone is brought to you in partnership with New Relic. Quickly learn how to use Docke ...
- 通过docker-composer启动容器nginx,并完成spring.boot的web站点端口转发
前面已经讲过2篇基于docker的mysql.redis容器编排并启动.这次将练习下nginx的docker方式的部署,以及通过nginx去代理宿主主机上的Web服务应该怎么配 PS:(这里由于ngi ...
- spring cloud:搭建基于consul的服务提供者集群(spring cloud hoxton sr8 / spring boot 2.3.4)
一,搭建基于consul的服务提供者集群 1,consul集群,共3个实例: 2, 服务提供者集群:共2个实例: 3,服务消费者:一个实例即可 4,consul集群的搭建,请参考: https://w ...
- 玩转spring boot——快速开始
开发环境: IED环境:Eclipse JDK版本:1.8 maven版本:3.3.9 一.创建一个spring boot的mcv web应用程序 打开Eclipse,新建Maven项目 选择quic ...
- 【微框架】之一:从零开始,轻松搞定SpringCloud微框架系列--开山篇(spring boot 小demo)
Spring顶级框架有众多,那么接下的篇幅,我将重点讲解SpringCloud微框架的实现 Spring 顶级项目,包含众多,我们重点学习一下,SpringCloud项目以及SpringBoot项目 ...
- 玩转spring boot——开篇
很久没写博客了,而这一转眼就是7年.这段时间并不是我没学习东西,而是园友们的技术提高的非常快,这反而让我不知道该写些什么.我做程序已经有十几年之久了,可以说是彻彻底底的“程序老炮”,至于技术怎么样?我 ...
- 玩转spring boot——结合redis
一.准备工作 下载redis的windows版zip包:https://github.com/MSOpenTech/redis/releases 运行redis-server.exe程序 出现黑色窗口 ...
随机推荐
- 解决Unable to load component class org.sonar.scanner.report.ActiveRulesPublisher/Unable to load component interface org.sonar.api.batch.rule.ActiveRules: NullPointerException
解决办法 Delete the directory data/es in your SonarQube installation. Restart SonarQube.
- Oracle-client支持exp|imp|rman
官方精简版的驱动,不支持持exp/imp/rman,故需要安装oracle_client客户端. 实验环境: Centos6.5 x64 Oracle 11.2.0.4.0 Oracle_clie ...
- Android仿掌上英雄联盟首页,实现折叠效果
概述 仿掌上英雄联盟首页的demo 详细 代码下载:http://www.demodashi.com/demo/10695.html 首页大概分为几个部分 状态栏 标题栏 轮播图 切换的Tab 资讯列 ...
- 【php】实现多个一维数组转换成二维循环数组
1.目的:将下面类型数组转换成模板循环打印二维数组 数组库一维数组: 模板要求循环二维数组: 2.代码: header("Content-type: text/html; charset=u ...
- 【QRcode二维码】:使用JS前端插件QRcode.js生成二维码
1.先简单说一下jquery-qrcode,这个开源的三方库(可以从https://github.com/jeromeetienne/jquery-qrcode 获取), qrcode.js 是实现二 ...
- mysql中innodb和myisam的区别
InnoDB和MyISAM是很多人在使用MySQL时最常用的两个表类型,这两个表类型各有优劣,5.7之后就不一样了 1.事务和外键 InnoDB具有事务,支持4个事务隔离级别,回滚,崩溃修复能力和多版 ...
- SQLAlchemy基本使用(Flask中)
SQLAlchemy介绍 SQLAlchemy是一个基于Python实现的ORM框架. 该框架建立在 DB API之上,使用关系对象映射进行数据库操作,简言之便是:将类和对象转换成SQL,然后使用数据 ...
- HDUOJ---2642Stars(二维树状数组)
Stars Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others)Total Submi ...
- 'Provide value on 'System.Windows.StaticResourceExtension' threw an exception.'
产生这个错误的原因是,StaticResource必须先定义再引用,但是DynamicResource就没有这个限制,为避免这个错误出现,可将StaticResource的定义放在Window.xam ...
- AP_应付模组在月结的处理
2014-06-04 Created By BaoXinjian 1. 完成所有交易及检查Interface (1). Invoice and Credits (2). Prepa ...