UnknownHostException as resource-not-found for properties files
Plus first-class declaration of FileNotFoundException in Resource javadoc. Issue: SPR-15433
This commit is contained in:
parent
ce4eff321c
commit
c4e0d6c2a2
|
|
@ -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()) {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
* <p>It is expected that each call creates a <i>fresh</i> stream.
|
||||
* <p>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 <i>required</i>
|
||||
* 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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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}.
|
||||
* <p>It is expected that each call creates a <i>fresh</i> channel.
|
||||
* <p>The default implementation returns {@link Channels#newChannel(InputStream)} with the
|
||||
* result of {@link #getInputStream()}.
|
||||
* <p>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());
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
Loading…
Reference in New Issue