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程序 出现黑色窗口 ...
随机推荐
- git删除本地的资源,如何恢复?
1.$ git reset --hard HEAD 将提交重置 2.使用 $ git checkout TestTimer.java(文件名) 恢复过来了
- JAR,WAR,EAR区别
JAR WAR EAR 英文 Java Archive file Web Archive file Enterprise Archive file 包含内容 class.properties文件,是文 ...
- js的7个技巧
http://www.vaikan.com/seven-javascript-things-i-wish-i-knew-much-earlier-in-my-career/
- you need to know those webs !
J2me开发网 http://www.j2medev.com/bbs/index.asp J2me社区 http://www.j2meforums.com/forum/ csdn http://www ...
- HDUOJ-----2065"红色病毒"问题
"红色病毒"问题 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- Python 的 if __name__ == '__main__'
Python 文件 最后部分会有: if __name__ == '__main__': TestRLSO()……………… 1)首先,这是一个判断语句. 表示执行的是此代码所在的文件.如果这个文件是作 ...
- CSS:关于CSS Hack
CSS Hack由于不同厂商的浏览器,如Internet Explorer,Safari,Mozilla Firefox,Chrome 等,或者是同一厂商的浏览器的不同版本,如IE6和IE7,对CSS ...
- 内存管理算法--Buddy伙伴算法【转】
转自:http://blog.csdn.net/orange_os/article/details/7392986 Buddy算法的优缺点: 1)尽管伙伴内存算法在内存碎片问题上已经做的相当出色,但是 ...
- LaTeX多文件编译的方法总结
LaTeX多文件编译的方法总结 在编写LaTeX文档的时候,由于文档的section较多,或者section的编写时间各不相同,我们可能碰到如下问题: 1.由于想分开编写各个section 2.pre ...
- Android开发8——利用pull解析器读写XML文件
一.基本介绍 对XML解析有SAX和DOM等多种方式,Android中极力推荐xmlpull方式解析xml.xmlpull不仅可用在Android上同样也适用于javase,但在javase环境中需自 ...