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程序 出现黑色窗口 ...
随机推荐
- html字符转义
常用表: No. 文字表記 10進表記 16進表記 文字 Comment 001 " " " """ quotation mark ...
- 11个强大的 Visual Studio 调试技能
简介 调试是软件开辟周期中很首要的一项目组.它具有挑衅性,同时也很让人困惑和懊恼.总的来说,对于稍大一点的法度,调试是不成避免的.比来几年,调试对象的成长让很多调试任务变的越来越简单和省时. 这篇文章 ...
- ASP.NET 性能监控和优化入门
关键要点: 只有与应用指标相关联,基础设施指标才能最大发挥作用. 高效性能优化的关键在于性能数据. 一些APM工具为ASP.NET提供了开箱即用的支持,这样入门使用ASP.NET仅需最小限度的初始设置 ...
- Linux 系统sudo命令
Linux系统中有许多的系统命令和服务为了安全性考虑,因此只有root超级用户才可以去使用.如果普通用户需要做此类操作,则可以使用su - 命令(减号(-)指完全切换到新的用户,即把环境变量信息也变更 ...
- Android API之android.provider.ContactsContract.Contacts
android.provider.ContactsContract.Contacts 对应contacts数据表.RawContacts的一个聚合(aggregate)代表同一个人.每个人在数据表co ...
- mysql中的order by
一.order by的原理 1.利用索引的有序性获取有序数据 当查询语句的 order BY 条件和查询的执行计划中所利用的 Index 的索引键(或前面几个索引键)完全一致,且索引访问方式为 ran ...
- HDUOJ----Good Numbers
Good Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- 总结PLSQL的快捷键以及使用技巧
http://www.dedecms.com/knowledge/data-base/oracle/2012/0724/3643.html 最近在开发过程中,遇到一些麻烦,就是开发效率问题,有时候其他 ...
- Python练习笔记——字符串反转
请输入一段字符串,不利用反转函数,编写一段代码,将其反转. def list_reverse(a): list_long = len(a) list_long_half = list_long // ...
- OGG_GoldenGate目标端库级别数据初始化(案例)
2014-03-07 Created By BaoXinjian