Add InvalidConfigurationPropertyValueException

This commit adds a new exception type that denotes the value of a
configuration key is invalid, alongside a FailureAnalyzer that reports
a human-readable report when such exception is thrown on startup.

ResourceNotFoundException being a (useless) specialization of this new
exception, its usage has been refactored to use the more general
exception type.

Closes gh-10794
This commit is contained in:
Stephane Nicoll
2018-01-06 17:37:30 +01:00
parent 6daad1f562
commit b98c7ed9f8
6 changed files with 384 additions and 60 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -25,7 +25,7 @@ import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.context.config.ResourceNotFoundException;
import org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.jdbc.DataSourceInitializationMode;
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
@@ -166,7 +166,8 @@ class DataSourceInitializer {
resources.add(resource);
}
else if (validate) {
throw new ResourceNotFoundException(propertyName, resource);
throw new InvalidConfigurationPropertyValueException(propertyName,
resource, "the specified resource does not exist");
}
}
}