diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java index 551e06acc17..1985f419a2f 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java @@ -18,6 +18,7 @@ package org.springframework.context.annotation; import java.io.FileNotFoundException; import java.io.IOException; +import java.net.UnknownHostException; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; @@ -442,7 +443,7 @@ class ConfigurationClassParser { Resource resource = this.resourceLoader.getResource(resolvedLocation); addPropertySource(factory.createPropertySource(name, new EncodedResource(resource, encoding))); } - catch (IllegalArgumentException | FileNotFoundException ex) { + catch (IllegalArgumentException | FileNotFoundException | UnknownHostException ex) { // Placeholders not resolvable or resource not found when trying to open it if (ignoreResourceNotFound) { if (logger.isInfoEnabled()) { diff --git a/spring-core/src/main/java/org/springframework/core/io/InputStreamSource.java b/spring-core/src/main/java/org/springframework/core/io/InputStreamSource.java index 282ebb1eca7..0a1758ad147 100644 --- a/spring-core/src/main/java/org/springframework/core/io/InputStreamSource.java +++ b/spring-core/src/main/java/org/springframework/core/io/InputStreamSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,14 +41,15 @@ import java.io.InputStream; public interface InputStreamSource { /** - * Return an {@link InputStream}. + * Return an {@link InputStream} for the content of an underlying resource. *
It is expected that each call creates a fresh stream. *
This requirement is particularly important when you consider an API such * as JavaMail, which needs to be able to read the stream multiple times when * creating mail attachments. For such a use case, it is required * that each {@code getInputStream()} call returns a fresh stream. * @return the input stream for the underlying resource (must not be {@code null}) - * @throws IOException if the stream could not be opened + * @throws java.io.FileNotFoundException if the underlying resource doesn't exist + * @throws IOException if the content stream could not be opened */ InputStream getInputStream() throws IOException; diff --git a/spring-core/src/main/java/org/springframework/core/io/Resource.java b/spring-core/src/main/java/org/springframework/core/io/Resource.java index 1dbffa90e98..c26c27754c8 100644 --- a/spring-core/src/main/java/org/springframework/core/io/Resource.java +++ b/spring-core/src/main/java/org/springframework/core/io/Resource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -109,19 +109,23 @@ public interface Resource extends InputStreamSource { /** * Return a File handle for this resource. - * @throws IOException if the resource cannot be resolved as absolute - * file path, i.e. if the resource is not available in a file system + * @throws java.io.FileNotFoundException if the resource cannot be resolved as + * absolute file path, i.e. if the resource is not available in a file system + * @throws IOException in case of general resolution/reading failures + * @see #getInputStream() */ File getFile() throws IOException; /** * Return a {@link ReadableByteChannel}. *
It is expected that each call creates a fresh channel. - *
The default implementation returns {@link Channels#newChannel(InputStream)} with the - * result of {@link #getInputStream()}. + *
The default implementation returns {@link Channels#newChannel(InputStream)} + * with the result of {@link #getInputStream()}. * @return the byte channel for the underlying resource (must not be {@code null}) - * @throws IOException if the channel could not be opened + * @throws java.io.FileNotFoundException if the underlying resource doesn't exist + * @throws IOException if the content channel could not be opened * @since 5.0 + * @see #getInputStream() */ default ReadableByteChannel readableChannel() throws IOException { return Channels.newChannel(getInputStream()); diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java b/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java index 88edb0ec8a3..726c4fadb88 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java @@ -18,6 +18,7 @@ package org.springframework.core.io.support; import java.io.FileNotFoundException; import java.io.IOException; +import java.net.UnknownHostException; import java.util.Properties; import org.apache.commons.logging.Log; @@ -176,7 +177,7 @@ public abstract class PropertiesLoaderSupport { PropertiesLoaderUtils.fillProperties( props, new EncodedResource(location, this.fileEncoding), this.propertiesPersister); } - catch (FileNotFoundException ex) { + catch (FileNotFoundException | UnknownHostException ex) { if (this.ignoreResourceNotFound) { if (logger.isInfoEnabled()) { logger.info("Properties resource not found: " + ex.getMessage());