Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
8aaf95b7
Commit
8aaf95b7
authored
Jan 12, 2018
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
270acd46
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
13 deletions
+20
-13
DataSourceInitializer.java
...mework/boot/autoconfigure/jdbc/DataSourceInitializer.java
+1
-1
InvalidConfigurationPropertyValueException.java
...es/source/InvalidConfigurationPropertyValueException.java
+12
-0
InvalidConfigurationPropertyValueFailureAnalyzer.java
...zer/InvalidConfigurationPropertyValueFailureAnalyzer.java
+1
-1
InvalidConfigurationPropertyValueFailureAnalyzerTests.java
...nvalidConfigurationPropertyValueFailureAnalyzerTests.java
+6
-11
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java
View file @
8aaf95b7
...
@@ -167,7 +167,7 @@ class DataSourceInitializer {
...
@@ -167,7 +167,7 @@ class DataSourceInitializer {
}
}
else
if
(
validate
)
{
else
if
(
validate
)
{
throw
new
InvalidConfigurationPropertyValueException
(
propertyName
,
throw
new
InvalidConfigurationPropertyValueException
(
propertyName
,
resource
,
"
the specified resource does not exist
"
);
resource
,
"
The specified resource does not exist.
"
);
}
}
}
}
}
}
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/InvalidConfigurationPropertyValueException.java
View file @
8aaf95b7
...
@@ -16,6 +16,8 @@
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
boot
.
context
.
properties
.
source
;
package
org
.
springframework
.
boot
.
context
.
properties
.
source
;
import
org.springframework.util.Assert
;
/**
/**
* Exception thrown when a configuration property value is invalid.
* Exception thrown when a configuration property value is invalid.
*
*
...
@@ -31,9 +33,19 @@ public class InvalidConfigurationPropertyValueException extends RuntimeException
...
@@ -31,9 +33,19 @@ public class InvalidConfigurationPropertyValueException extends RuntimeException
private
final
String
reason
;
private
final
String
reason
;
/**
* Creates a new instance for the specified property {@code name} and {@code value},
* including a {@code reason} why the value is invalid.
* @param name the name of the property in canonical format
* @param value the value of the property, can be {@code null}
* @param reason a human-readable text that describes why the reason is invalid.
* Starts with an upper-case and ends with a dots. Several sentences and carriage
* returns are allowed.
*/
public
InvalidConfigurationPropertyValueException
(
String
name
,
Object
value
,
public
InvalidConfigurationPropertyValueException
(
String
name
,
Object
value
,
String
reason
)
{
String
reason
)
{
super
(
"Property "
+
name
+
" with value '"
+
value
+
"' is invalid: "
+
reason
);
super
(
"Property "
+
name
+
" with value '"
+
value
+
"' is invalid: "
+
reason
);
Assert
.
notNull
(
name
,
"Name must not be null"
);
this
.
name
=
name
;
this
.
name
=
name
;
this
.
value
=
value
;
this
.
value
=
value
;
this
.
reason
=
reason
;
this
.
reason
=
reason
;
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/InvalidConfigurationPropertyValueFailureAnalyzer.java
View file @
8aaf95b7
...
@@ -94,7 +94,7 @@ class InvalidConfigurationPropertyValueFailureAnalyzer
...
@@ -94,7 +94,7 @@ class InvalidConfigurationPropertyValueFailureAnalyzer
private
void
appendReason
(
StringBuilder
message
,
private
void
appendReason
(
StringBuilder
message
,
InvalidConfigurationPropertyValueException
cause
)
{
InvalidConfigurationPropertyValueException
cause
)
{
if
(
StringUtils
.
hasText
(
cause
.
getReason
()))
{
if
(
StringUtils
.
hasText
(
cause
.
getReason
()))
{
message
.
append
(
" Validation failed for the following reason\n\n"
);
message
.
append
(
" Validation failed for the following reason
:
\n\n"
);
message
.
append
(
cause
.
getReason
());
message
.
append
(
cause
.
getReason
());
}
}
else
{
else
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/InvalidConfigurationPropertyValueFailureAnalyzerTests.java
View file @
8aaf95b7
...
@@ -22,7 +22,6 @@ import org.junit.Test;
...
@@ -22,7 +22,6 @@ import org.junit.Test;
import
org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException
;
import
org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException
;
import
org.springframework.boot.diagnostics.FailureAnalysis
;
import
org.springframework.boot.diagnostics.FailureAnalysis
;
import
org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter
;
import
org.springframework.boot.origin.Origin
;
import
org.springframework.boot.origin.Origin
;
import
org.springframework.boot.origin.OriginLookup
;
import
org.springframework.boot.origin.OriginLookup
;
import
org.springframework.core.env.EnumerablePropertySource
;
import
org.springframework.core.env.EnumerablePropertySource
;
...
@@ -43,7 +42,7 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
...
@@ -43,7 +42,7 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
@Test
@Test
public
void
analysisWithNullEnvironment
()
{
public
void
analysisWithNullEnvironment
()
{
InvalidConfigurationPropertyValueException
failure
=
new
InvalidConfigurationPropertyValueException
(
InvalidConfigurationPropertyValueException
failure
=
new
InvalidConfigurationPropertyValueException
(
"test.property"
,
"invalid"
,
"
this is not valid
"
);
"test.property"
,
"invalid"
,
"
This is not valid.
"
);
FailureAnalysis
analysis
=
new
InvalidConfigurationPropertyValueFailureAnalyzer
()
FailureAnalysis
analysis
=
new
InvalidConfigurationPropertyValueFailureAnalyzer
()
.
analyze
(
failure
);
.
analyze
(
failure
);
assertThat
(
analysis
).
isNull
();
assertThat
(
analysis
).
isNull
();
...
@@ -56,12 +55,12 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
...
@@ -56,12 +55,12 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
this
.
environment
.
getPropertySources
()
this
.
environment
.
getPropertySources
()
.
addFirst
(
OriginCapablePropertySource
.
get
(
source
));
.
addFirst
(
OriginCapablePropertySource
.
get
(
source
));
InvalidConfigurationPropertyValueException
failure
=
new
InvalidConfigurationPropertyValueException
(
InvalidConfigurationPropertyValueException
failure
=
new
InvalidConfigurationPropertyValueException
(
"test.property"
,
"invalid"
,
"
this is not valid
"
);
"test.property"
,
"invalid"
,
"
This is not valid.
"
);
FailureAnalysis
analysis
=
performAnalysis
(
failure
);
FailureAnalysis
analysis
=
performAnalysis
(
failure
);
assertCommonParts
(
failure
,
analysis
);
assertCommonParts
(
failure
,
analysis
);
assertThat
(
analysis
.
getDescription
())
assertThat
(
analysis
.
getDescription
())
.
contains
(
"Validation failed for the following reason"
)
.
contains
(
"Validation failed for the following reason"
)
.
contains
(
"
this is not valid
"
)
.
contains
(
"
This is not valid.
"
)
.
doesNotContain
(
"Additionally, this property is also set"
);
.
doesNotContain
(
"Additionally, this property is also set"
);
}
}
...
@@ -93,7 +92,7 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
...
@@ -93,7 +92,7 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
this
.
environment
.
getPropertySources
()
this
.
environment
.
getPropertySources
()
.
addLast
(
OriginCapablePropertySource
.
get
(
another
));
.
addLast
(
OriginCapablePropertySource
.
get
(
another
));
InvalidConfigurationPropertyValueException
failure
=
new
InvalidConfigurationPropertyValueException
(
InvalidConfigurationPropertyValueException
failure
=
new
InvalidConfigurationPropertyValueException
(
"test.property"
,
"invalid"
,
"
this is not valid
"
);
"test.property"
,
"invalid"
,
"
This is not valid.
"
);
FailureAnalysis
analysis
=
performAnalysis
(
failure
);
FailureAnalysis
analysis
=
performAnalysis
(
failure
);
assertCommonParts
(
failure
,
analysis
);
assertCommonParts
(
failure
,
analysis
);
assertThat
(
analysis
.
getDescription
())
assertThat
(
analysis
.
getDescription
())
...
@@ -106,7 +105,7 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
...
@@ -106,7 +105,7 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
@Test
@Test
public
void
analysisWithUnknownKey
()
{
public
void
analysisWithUnknownKey
()
{
InvalidConfigurationPropertyValueException
failure
=
new
InvalidConfigurationPropertyValueException
(
InvalidConfigurationPropertyValueException
failure
=
new
InvalidConfigurationPropertyValueException
(
"test.key.not.defined"
,
"invalid"
,
"
this is not valid
"
);
"test.key.not.defined"
,
"invalid"
,
"
This is not valid.
"
);
assertThat
(
performAnalysis
(
failure
)).
isNull
();
assertThat
(
performAnalysis
(
failure
)).
isNull
();
}
}
...
@@ -123,11 +122,7 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
...
@@ -123,11 +122,7 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
InvalidConfigurationPropertyValueException
failure
)
{
InvalidConfigurationPropertyValueException
failure
)
{
InvalidConfigurationPropertyValueFailureAnalyzer
analyzer
=
new
InvalidConfigurationPropertyValueFailureAnalyzer
();
InvalidConfigurationPropertyValueFailureAnalyzer
analyzer
=
new
InvalidConfigurationPropertyValueFailureAnalyzer
();
analyzer
.
setEnvironment
(
this
.
environment
);
analyzer
.
setEnvironment
(
this
.
environment
);
FailureAnalysis
analysis
=
analyzer
.
analyze
(
failure
);
return
analyzer
.
analyze
(
failure
);
if
(
analysis
!=
null
)
{
new
LoggingFailureAnalysisReporter
().
report
(
analysis
);
}
return
analysis
;
}
}
static
class
OriginCapablePropertySource
<
T
>
extends
EnumerablePropertySource
<
T
>
static
class
OriginCapablePropertySource
<
T
>
extends
EnumerablePropertySource
<
T
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment