mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +08:00
Prevent exception when loading optional config data locations
Closes gh-35683
This commit is contained in:
parent
303a8f0825
commit
b266ade00c
@ -226,6 +226,9 @@ public class StandardConfigDataLocationResolver
|
|||||||
return Collections.singleton(reference);
|
return Collections.singleton(reference);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (configDataLocation.isOptional()) {
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
throw new IllegalStateException("File extension is not known to any PropertySourceLoader. "
|
throw new IllegalStateException("File extension is not known to any PropertySourceLoader. "
|
||||||
+ "If the location is meant to reference a directory, it must end in '/' or File.separator");
|
+ "If the location is meant to reference a directory, it must end in '/' or File.separator");
|
||||||
}
|
}
|
||||||
|
@ -43,18 +43,19 @@ import static org.mockito.Mockito.mock;
|
|||||||
*
|
*
|
||||||
* @author Madhura Bhave
|
* @author Madhura Bhave
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
|
* @author Moritz Halbritter
|
||||||
*/
|
*/
|
||||||
class StandardConfigDataLocationResolverTests {
|
class StandardConfigDataLocationResolverTests {
|
||||||
|
|
||||||
private StandardConfigDataLocationResolver resolver;
|
private StandardConfigDataLocationResolver resolver;
|
||||||
|
|
||||||
private ConfigDataLocationResolverContext context = mock(ConfigDataLocationResolverContext.class);
|
private final ConfigDataLocationResolverContext context = mock(ConfigDataLocationResolverContext.class);
|
||||||
|
|
||||||
private MockEnvironment environment;
|
private MockEnvironment environment;
|
||||||
|
|
||||||
private Binder environmentBinder;
|
private Binder environmentBinder;
|
||||||
|
|
||||||
private ResourceLoader resourceLoader = new DefaultResourceLoader();
|
private final ResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setup() {
|
void setup() {
|
||||||
@ -260,6 +261,26 @@ class StandardConfigDataLocationResolverTests {
|
|||||||
assertThat(locations).isEmpty();
|
assertThat(locations).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void resolveWhenOptionalAndLoaderIsUnknownShouldNotFail() {
|
||||||
|
ConfigDataLocation location = ConfigDataLocation.of("optional:some-unknown-loader:dummy.properties");
|
||||||
|
assertThatNoException().isThrownBy(() -> this.resolver.resolve(this.context, location));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void resolveWhenOptionalAndLoaderIsUnknownAndExtensionIsUnknownShouldNotFail() {
|
||||||
|
ConfigDataLocation location = ConfigDataLocation
|
||||||
|
.of("optional:some-unknown-loader:dummy.some-unknown-extension");
|
||||||
|
List<StandardConfigDataResource> locations = this.resolver.resolve(this.context, location);
|
||||||
|
assertThatNoException().isThrownBy(() -> this.resolver.resolve(this.context, location));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void resolveWhenOptionalAndExtensionIsUnknownShouldNotFail() {
|
||||||
|
ConfigDataLocation location = ConfigDataLocation.of("optional:file:dummy.some-unknown-extension");
|
||||||
|
assertThatNoException().isThrownBy(() -> this.resolver.resolve(this.context, location));
|
||||||
|
}
|
||||||
|
|
||||||
private String filePath(String... components) {
|
private String filePath(String... components) {
|
||||||
return "file [" + String.join(File.separator, components) + "]";
|
return "file [" + String.join(File.separator, components) + "]";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user