As a first step towards #29481, driven by the deprecation of the java.net.URL constructors in JDK 20, we can factor out all URL construction to toURL methods in ResourceUtils, centralizing the use of java.net.URL constructors and therefore also their possible replacement in the future.

Also, UrlResource traditionally uses equality on a cleaned URL instance for comparisons. This can be replaced with a check on a cleaned URL String, sourced from either a URI or a URL instance.