2

I'm trying to load a HTTP zip file with UrlResource:

new UrlResource("url:http://www.my-path.to/file.zip")

Result.

Caused by: java.io.FileNotFoundException: URL [http://www.my-path.to/file.zip] cannot be resolved to absolute file path because it does not reside in the file system.

What is the correct way of loading a HTTP file with the Resource interface?

I later on want to add that Resource to an ItemReader for Spring Batch.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
membersound
  • 81,582
  • 193
  • 585
  • 1,120

1 Answers1

4

You need to use the http: prefix instead of url: to reference a HTTP resource with UrlResource.

Quoting from Spring documentation:

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.

As such, you would just have new UrlResource("http://www.my-path.to/file.zip").

Tunaki
  • 132,869
  • 46
  • 340
  • 423