RSS Feeds with Spring Boot
来源:互联网 发布:mysql结构化查询语言 编辑:程序博客网 时间:2024/09/21 06:35
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, AbstractRssFeedView and other supporting classes.
In (1) you'll see we're extending Spring's AbstractRssFeedView class. 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 with ApplicationSettings from an external properties file(2). We retrieve our Post List, stream it, modify it with our createItem(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 the RomeTools dependency in build.gradle.
compile 'com.rometools:rome:1.6.1'
The Controller
Now that we've created our Spring RssPostView all we have to do is add it to our model. Notice we're addingthe 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…
@Overridepublic void configureViewResolvers(ViewResolverRegistry registry) {registry.enableContentNegotiation(new RssPostFeedView());}
…in a WebMvcConfigurer class. This is no longer needed, which is very wonderful.
The Test
Here's a quick test to confirm we're delivering media with content type application/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
- RSS feeds with Java
- Syndicating Web Sites with RSS Feeds For Dummies
- PeopleSoft and RSS feeds
- RSS Feeds List
- 更精确的RSS Feeds搜索引擎 - Feedmil
- spring-boot with docker
- 18. RSS订阅(RSS Feeds)and price rule
- INTEGRATING SPRING SECURITY WITH SPRING BOOT WEB
- Spring Boot with Spring MVC Application
- 现实简单的RSS订阅功能,对RSS feeds的分析
- Spring Boot With JSPs in Executable Jars
- Securing REST APIs With Spring Boot
- Spring-boot JDBC with multiple DataSources sample
- Spring boot JPA column with incorrect underscore
- Spring boot 之 Cache With Redis
- Head Fisrt Android Development读书笔记(2)Working with Feeds
- Content Syndication with RSS
- 工业大数据漫谈12:实时数据库与时序数据库
- 蓝牙LL数据包交互【More Data多数据传输】【Acknowledgement and Flow Control】
- Java实现字符串反转
- jQuery选择器
- jQuery中的事件
- RSS Feeds with Spring Boot
- Android Preference使用
- 二分+堆——Codeforces812C Sagheer and Nubian Market
- 芯片相关工艺01——芯片反向工程
- spfa||贪心——洛谷P1250 种树
- spring 框架说明文档学习记录(3.5)
- rex run
- Oracle中保留两位小数
- #pragma warning(disable:4996)