Spring Batch: Create an ItemReader that reads an xml file from a web service

假装没事ソ 提交于 2019-12-05 11:05:12

The StaxEventItemReader takes a Resource. Take a look at the documentation, you will see that you can easily use a resource that is not on your filesystem. Anything on which you can get an InputStream can probably be converted to a Resource. The default use an UrlResource with a fallback to ClasspathResource as far as I remember.

4.3.1. UrlResource

The UrlResource wraps a java.net.URL, and may be used to access any object that is normally accessible via a URL, such as files, an HTTP target, an FTP target, etc. All URLs have a standardized String representation, such that appropriate standardized prefixes are used to indicate one URL type from another. This includes file: for accessing filesystem paths, http: for accessing resources via the HTTP protocol, ftp: for accessing resources via FTP, etc. A UrlResource is created by Java code explicitly using the UrlResource constructor, but will often be created implicitly when you call an API method which takes a String argument which is meant to represent a path. For the latter case, a JavaBeans PropertyEditor will ultimately decide which type of Resource to create. If the path string contains a few well-known (to it, that is) prefixes such as classpath:, it will create an appropriate specialized Resource for that prefix. However, if it doesn't recognize the prefix, it will assume the this is just a standard URL string, and will create a UrlResource.

So you can probably just use this:

<property name="resource" value="http://www.w3schools.com/xml/plant_catalog.xml" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!