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
324a00fd
Commit
324a00fd
authored
Sep 15, 2017
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
796d4003
Changes
26
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
189 additions
and
226 deletions
+189
-226
EndpointEnablementProvider.java
...te/autoconfigure/endpoint/EndpointEnablementProvider.java
+2
-1
ConditionalOnEnabledEndpoint.java
...gure/endpoint/condition/ConditionalOnEnabledEndpoint.java
+4
-4
ConfigurationPropertiesReportEndpointAutoConfigurationTests.java
...rationPropertiesReportEndpointAutoConfigurationTests.java
+7
-6
EndpointEnablementProviderTests.java
...toconfigure/endpoint/EndpointEnablementProviderTests.java
+17
-34
EnvironmentEndpointAutoConfigurationTests.java
...figure/env/EnvironmentEndpointAutoConfigurationTests.java
+0
-2
HealthEndpointAutoConfigurationTests.java
...onfigure/health/HealthEndpointAutoConfigurationTests.java
+2
-2
JmxEndpointIntegrationTests.java
...onfigure/integrationtest/JmxEndpointIntegrationTests.java
+4
-6
LogFileWebEndpointManagementContextConfigurationTests.java
...ogFileWebEndpointManagementContextConfigurationTests.java
+12
-12
RequestMappingEndpointTests.java
...utoconfigure/web/servlet/RequestMappingEndpointTests.java
+1
-1
AnnotationEndpointDiscoverer.java
...ate/endpoint/annotation/AnnotationEndpointDiscoverer.java
+2
-2
SecurityProperties.java
...ework/boot/autoconfigure/security/SecurityProperties.java
+2
-2
NonUniqueSessionRepositoryException.java
...onfigure/session/NonUniqueSessionRepositoryException.java
+3
-4
NonUniqueSessionRepositoryFailureAnalyzer.java
...re/session/NonUniqueSessionRepositoryFailureAnalyzer.java
+1
-3
SessionAutoConfiguration.java
.../boot/autoconfigure/session/SessionAutoConfiguration.java
+3
-6
ResourceProperties.java
...gframework/boot/autoconfigure/web/ResourceProperties.java
+0
-1
WebMvcAutoConfiguration.java
...ot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java
+30
-26
OAuth2RestOperationsConfigurationTests.java
...oauth2/client/OAuth2RestOperationsConfigurationTests.java
+2
-2
SessionAutoConfigurationHazelcastTests.java
...igure/session/SessionAutoConfigurationHazelcastTests.java
+8
-9
SessionAutoConfigurationIntegrationTests.java
...ure/session/SessionAutoConfigurationIntegrationTests.java
+18
-19
SessionAutoConfigurationJdbcTests.java
...oconfigure/session/SessionAutoConfigurationJdbcTests.java
+9
-12
SessionAutoConfigurationRedisTests.java
...configure/session/SessionAutoConfigurationRedisTests.java
+4
-5
SessionAutoConfigurationTests.java
.../autoconfigure/session/SessionAutoConfigurationTests.java
+10
-11
ConfigurationMetadataAnnotationProcessor.java
...onprocessor/ConfigurationMetadataAnnotationProcessor.java
+2
-2
ConfigurationMetadataAnnotationProcessorTests.java
...cessor/ConfigurationMetadataAnnotationProcessorTests.java
+43
-54
DefaultEnablement.java
...framework/boot/configurationsample/DefaultEnablement.java
+1
-0
ConfigurationPropertiesBinderBuilder.java
...text/properties/ConfigurationPropertiesBinderBuilder.java
+2
-0
No files found.
spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/EndpointEnablementProvider.java
View file @
324a00fd
...
...
@@ -100,7 +100,8 @@ public class EndpointEnablementProvider {
if
(
result
!=
null
)
{
return
result
;
}
boolean
enablement
=
determineGlobalDefaultEnablement
(
defaultEnablement
,
exposure
);
boolean
enablement
=
determineGlobalDefaultEnablement
(
defaultEnablement
,
exposure
);
String
message
=
determineGlobalDefaultMessage
(
endpointId
,
enablement
,
exposure
,
defaultEnablement
);
return
new
EndpointEnablement
(
enablement
,
message
);
...
...
spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnEnabledEndpoint.java
View file @
324a00fd
...
...
@@ -48,10 +48,10 @@ import org.springframework.context.annotation.Conditional;
* If any properties are set, they are evaluated from most to least specific, e.g.
* considering a web endpoint with id {@code foo}:
* <ol>
*
<li>endpoints.foo.web.enabled</li>
*
<li>endpoints.foo.enabled</li>
*
<li>endpoints.default.web.enabled</li>
*
<li>endpoints.default.enabled</li>
* <li>endpoints.foo.web.enabled</li>
* <li>endpoints.foo.enabled</li>
* <li>endpoints.default.web.enabled</li>
* <li>endpoints.default.enabled</li>
* </ol>
* For instance if {@code endpoints.default.enabled} is {@code false} but
* {@code endpoints.<name>.enabled} is {@code true}, the condition will match.
...
...
spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfigurationTests.java
View file @
324a00fd
...
...
@@ -61,15 +61,16 @@ public class ConfigurationPropertiesReportEndpointAutoConfigurationTests {
@Test
public
void
keysToSanitizeCanBeConfiguredViaTheEnvironment
()
throws
Exception
{
this
.
contextRunner
.
withUserConfiguration
(
Config
.
class
)
.
withPropertyValues
(
"endpoints.configprops.keys-to-sanitize: .*pass.*, property"
)
.
withPropertyValues
(
"endpoints.configprops.keys-to-sanitize: .*pass.*, property"
)
.
run
(
validateTestProperties
(
"******"
,
"******"
));
}
private
ContextConsumer
<
AssertableApplicationContext
>
validateTestProperties
(
String
dbPassword
,
String
myTestProperty
)
{
private
ContextConsumer
<
AssertableApplicationContext
>
validateTestProperties
(
String
dbPassword
,
String
myTestProperty
)
{
return
context
->
{
assertThat
(
context
)
.
hasSingleBean
(
ConfigurationPropertiesReportEndpoint
.
class
);
assertThat
(
context
)
.
hasSingleBean
(
ConfigurationPropertiesReportEndpoint
.
class
);
ConfigurationPropertiesReportEndpoint
endpoint
=
context
.
getBean
(
ConfigurationPropertiesReportEndpoint
.
class
);
ConfigurationPropertiesDescriptor
properties
=
endpoint
...
...
@@ -94,7 +95,7 @@ public class ConfigurationPropertiesReportEndpointAutoConfigurationTests {
}
@ConfigurationProperties
(
"test"
)
private
static
class
TestProperties
{
static
class
TestProperties
{
private
String
dbPassword
=
"123456"
;
...
...
spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/EndpointEnablementProviderTests.java
View file @
324a00fd
...
...
@@ -127,16 +127,14 @@ public class EndpointEnablementProviderTests {
public
void
defaultEnablementNeutral
()
{
EndpointEnablement
enablement
=
getEndpointEnablement
(
"biz"
,
DefaultEnablement
.
NEUTRAL
);
validate
(
enablement
,
true
,
"endpoint 'biz' is enabled (default)"
);
validate
(
enablement
,
true
,
"endpoint 'biz' is enabled (default)"
);
}
@Test
public
void
defaultEnablementNeutralWeb
()
{
EndpointEnablement
enablement
=
getEndpointEnablement
(
"biz"
,
DefaultEnablement
.
NEUTRAL
,
EndpointExposure
.
WEB
);
validate
(
enablement
,
false
,
"endpoint 'default' (web) is disabled by default"
);
validate
(
enablement
,
false
,
"endpoint 'default' (web) is disabled by default"
);
}
@Test
...
...
@@ -151,8 +149,7 @@ public class EndpointEnablementProviderTests {
public
void
defaultEnablementNeutralWithGeneralDisablement
()
{
EndpointEnablement
enablement
=
getEndpointEnablement
(
"biz"
,
DefaultEnablement
.
NEUTRAL
,
"endpoints.default.enabled=false"
);
validate
(
enablement
,
false
,
"found property endpoints.default.enabled"
);
validate
(
enablement
,
false
,
"found property endpoints.default.enabled"
);
}
@Test
...
...
@@ -160,18 +157,15 @@ public class EndpointEnablementProviderTests {
EndpointEnablement
enablement
=
getEndpointEnablement
(
"biz"
,
DefaultEnablement
.
NEUTRAL
,
EndpointExposure
.
JMX
,
"endpoints.default.jmx.enabled=false"
);
validate
(
enablement
,
false
,
"found property endpoints.default.jmx.enabled"
);
validate
(
enablement
,
false
,
"found property endpoints.default.jmx.enabled"
);
}
@Test
public
void
defaultEnablementNeutralTechTakesPrecedence
()
{
EndpointEnablement
enablement
=
getEndpointEnablement
(
"biz"
,
DefaultEnablement
.
NEUTRAL
,
EndpointExposure
.
JMX
,
"endpoints.default.enabled=true"
,
"endpoints.default.jmx.enabled=false"
);
validate
(
enablement
,
false
,
"found property endpoints.default.jmx.enabled"
);
"endpoints.default.enabled=true"
,
"endpoints.default.jmx.enabled=false"
);
validate
(
enablement
,
false
,
"found property endpoints.default.jmx.enabled"
);
}
@Test
...
...
@@ -179,8 +173,7 @@ public class EndpointEnablementProviderTests {
EndpointEnablement
enablement
=
getEndpointEnablement
(
"biz"
,
DefaultEnablement
.
NEUTRAL
,
EndpointExposure
.
WEB
,
"endpoints.default.web.enabled=true"
);
validate
(
enablement
,
true
,
"found property endpoints.default.web.enabled"
);
validate
(
enablement
,
true
,
"found property endpoints.default.web.enabled"
);
}
@Test
...
...
@@ -196,8 +189,7 @@ public class EndpointEnablementProviderTests {
public
void
defaultEnablementNeutralWithOverride
()
{
EndpointEnablement
enablement
=
getEndpointEnablement
(
"biz"
,
DefaultEnablement
.
NEUTRAL
,
"endpoints.biz.enabled=false"
);
validate
(
enablement
,
false
,
"found property endpoints.biz.enabled"
);
validate
(
enablement
,
false
,
"found property endpoints.biz.enabled"
);
}
@Test
...
...
@@ -205,8 +197,7 @@ public class EndpointEnablementProviderTests {
EndpointEnablement
enablement
=
getEndpointEnablement
(
"biz"
,
DefaultEnablement
.
NEUTRAL
,
EndpointExposure
.
WEB
,
"endpoints.biz.web.enabled=true"
);
validate
(
enablement
,
true
,
"found property endpoints.biz.web.enabled"
);
validate
(
enablement
,
true
,
"found property endpoints.biz.web.enabled"
);
}
@Test
...
...
@@ -214,41 +205,33 @@ public class EndpointEnablementProviderTests {
EndpointEnablement
enablement
=
getEndpointEnablement
(
"biz"
,
DefaultEnablement
.
NEUTRAL
,
EndpointExposure
.
JMX
,
"endpoints.biz.jmx.enabled=false"
);
validate
(
enablement
,
false
,
"found property endpoints.biz.jmx.enabled"
);
validate
(
enablement
,
false
,
"found property endpoints.biz.jmx.enabled"
);
}
@Test
public
void
defaultEnablementNeutralTechTakesPrecedenceOnEverything
()
{
EndpointEnablement
enablement
=
getEndpointEnablement
(
"biz"
,
DefaultEnablement
.
NEUTRAL
,
EndpointExposure
.
JMX
,
"endpoints.default.enabled=false"
,
"endpoints.default.jmx.enabled=false"
,
"endpoints.biz.enabled=false"
,
"endpoints.biz.jmx.enabled=true"
);
validate
(
enablement
,
true
,
"found property endpoints.biz.jmx.enabled"
);
"endpoints.default.enabled=false"
,
"endpoints.default.jmx.enabled=false"
,
"endpoints.biz.enabled=false"
,
"endpoints.biz.jmx.enabled=true"
);
validate
(
enablement
,
true
,
"found property endpoints.biz.jmx.enabled"
);
}
@Test
public
void
defaultEnablementNeutralSpecificTakesPrecedenceOnDefaults
()
{
EndpointEnablement
enablement
=
getEndpointEnablement
(
"biz"
,
DefaultEnablement
.
NEUTRAL
,
EndpointExposure
.
JMX
,
"endpoints.default.enabled=false"
,
"endpoints.default.jmx.enabled=false"
,
"endpoints.default.enabled=false"
,
"endpoints.default.jmx.enabled=false"
,
"endpoints.biz.enabled=true"
);
validate
(
enablement
,
true
,
"found property endpoints.biz.enabled"
);
validate
(
enablement
,
true
,
"found property endpoints.biz.enabled"
);
}
@Test
public
void
defaultEnablementNeutralDefaultTechTakesPrecedenceOnGeneralDefault
()
{
EndpointEnablement
enablement
=
getEndpointEnablement
(
"biz"
,
DefaultEnablement
.
NEUTRAL
,
EndpointExposure
.
JMX
,
"endpoints.default.enabled=false"
,
"endpoints.default.jmx.enabled=true"
);
validate
(
enablement
,
true
,
"found property endpoints.default.jmx.enabled"
);
"endpoints.default.enabled=false"
,
"endpoints.default.jmx.enabled=true"
);
validate
(
enablement
,
true
,
"found property endpoints.default.jmx.enabled"
);
}
private
EndpointEnablement
getEndpointEnablement
(
String
id
,
...
...
spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointAutoConfigurationTests.java
View file @
324a00fd
...
...
@@ -56,7 +56,6 @@ public class EnvironmentEndpointAutoConfigurationTests {
.
doesNotHaveBean
(
EnvironmentEndpoint
.
class
));
}
@Test
public
void
keysToSanitizeCanBeConfiguredViaTheEnvironment
()
throws
Exception
{
this
.
contextRunner
.
withSystemProperties
(
"dbPassword=123456"
,
"apiKey=123456"
)
...
...
@@ -84,5 +83,4 @@ public class EnvironmentEndpointAutoConfigurationTests {
.
filter
((
source
)
->
name
.
equals
(
source
.
getName
())).
findFirst
().
get
();
}
}
spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfigurationTests.java
View file @
324a00fd
...
...
@@ -84,8 +84,8 @@ public class HealthEndpointAutoConfigurationTests {
@Test
public
void
runShouldHaveStatusEndpointBeanEvenIfDefaultIsDisabled
()
{
this
.
contextRunner
.
withPropertyValues
(
"endpoints.default.enabled:false"
)
.
run
(
(
context
)
->
assertThat
(
context
).
hasSingleBean
(
StatusEndpoint
.
class
));
this
.
contextRunner
.
withPropertyValues
(
"endpoints.default.enabled:false"
)
.
run
(
(
context
)
->
assertThat
(
context
).
hasSingleBean
(
StatusEndpoint
.
class
));
}
@Test
...
...
spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/JmxEndpointIntegrationTests.java
View file @
324a00fd
...
...
@@ -55,8 +55,7 @@ public class JmxEndpointIntegrationTests {
MBeanServer
mBeanServer
=
context
.
getBean
(
MBeanServer
.
class
);
checkEndpointMBeans
(
mBeanServer
,
new
String
[]
{
"autoconfig"
,
"beans"
,
"configprops"
,
"env"
,
"health"
,
"info"
,
"mappings"
,
"status"
,
"threaddump"
,
"trace"
},
"info"
,
"mappings"
,
"status"
,
"threaddump"
,
"trace"
},
new
String
[]
{
"shutdown"
});
});
}
...
...
@@ -68,8 +67,8 @@ public class JmxEndpointIntegrationTests {
MBeanServer
mBeanServer
=
context
.
getBean
(
MBeanServer
.
class
);
checkEndpointMBeans
(
mBeanServer
,
new
String
[
0
],
new
String
[]
{
"autoconfig"
,
"beans"
,
"configprops"
,
"env"
,
"health"
,
"mappings"
,
"shutdown"
,
"t
hreaddump"
,
"t
race"
});
"health"
,
"mappings"
,
"shutdown"
,
"threaddump"
,
"trace"
});
});
}
...
...
@@ -81,8 +80,7 @@ public class JmxEndpointIntegrationTests {
MBeanServer
mBeanServer
=
context
.
getBean
(
MBeanServer
.
class
);
checkEndpointMBeans
(
mBeanServer
,
new
String
[]
{
"beans"
},
new
String
[]
{
"autoconfig"
,
"configprops"
,
"env"
,
"health"
,
"mappings"
,
"shutdown"
,
"threaddump"
,
"trace"
});
"mappings"
,
"shutdown"
,
"threaddump"
,
"trace"
});
});
}
...
...
spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointManagementContextConfigurationTests.java
View file @
324a00fd
...
...
@@ -44,7 +44,6 @@ public class LogFileWebEndpointManagementContextConfigurationTests {
@Rule
public
TemporaryFolder
temp
=
new
TemporaryFolder
();
private
WebApplicationContextRunner
contextRunner
=
new
WebApplicationContextRunner
()
.
withUserConfiguration
(
LogFileWebEndpointManagementContextConfiguration
.
class
);
...
...
@@ -81,18 +80,19 @@ public class LogFileWebEndpointManagementContextConfigurationTests {
@Test
public
void
logFileWebEndpointUsesConfiguredExternalFile
()
throws
IOException
{
File
file
=
this
.
temp
.
newFile
(
"logfile"
);
FileCopyUtils
.
copy
(
"--TEST--"
.
getBytes
(),
file
);
FileCopyUtils
.
copy
(
"--TEST--"
.
getBytes
(),
file
);
this
.
contextRunner
.
withPropertyValues
(
"endpoints.logfile.external-file:"
+
file
.
getAbsolutePath
()).
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
LogFileWebEndpoint
.
class
);
LogFileWebEndpoint
endpoint
=
context
.
getBean
(
LogFileWebEndpoint
.
class
);
Resource
resource
=
endpoint
.
logFile
();
assertThat
(
resource
).
isNotNull
();
assertThat
(
StreamUtils
.
copyToString
(
resource
.
getInputStream
(),
StandardCharsets
.
UTF_8
)).
isEqualTo
(
"--TEST--"
);
});
.
withPropertyValues
(
"endpoints.logfile.external-file:"
+
file
.
getAbsolutePath
())
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
LogFileWebEndpoint
.
class
);
LogFileWebEndpoint
endpoint
=
context
.
getBean
(
LogFileWebEndpoint
.
class
);
Resource
resource
=
endpoint
.
logFile
();
assertThat
(
resource
).
isNotNull
();
assertThat
(
StreamUtils
.
copyToString
(
resource
.
getInputStream
(),
StandardCharsets
.
UTF_8
)).
isEqualTo
(
"--TEST--"
);
});
}
}
spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/RequestMappingEndpointTests.java
View file @
324a00fd
...
...
@@ -142,7 +142,7 @@ public class RequestMappingEndpointTests {
WebMvcEndpointHandlerMapping
mapping
=
new
WebMvcEndpointHandlerMapping
(
new
EndpointMapping
(
"application"
),
Collections
.
singleton
(
new
EndpointInfo
<>(
"test"
,
DefaultEnablement
.
ENABLED
,
Collections
.
singleton
(
operation
))));
DefaultEnablement
.
ENABLED
,
Collections
.
singleton
(
operation
))));
mapping
.
setApplicationContext
(
new
StaticApplicationContext
());
mapping
.
afterPropertiesSet
();
return
mapping
;
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/annotation/AnnotationEndpointDiscoverer.java
View file @
324a00fd
...
...
@@ -119,8 +119,8 @@ public abstract class AnnotationEndpointDiscoverer<T extends Operation, K>
private
EndpointInfo
<
T
>
createEndpointInfo
(
String
beanName
,
Class
<?>
beanType
,
AnnotationAttributes
attributes
)
{
String
id
=
attributes
.
getString
(
"id"
);
DefaultEnablement
defaultEnablement
=
(
DefaultEnablement
)
attributes
.
get
(
"defaultEnablement"
);
DefaultEnablement
defaultEnablement
=
(
DefaultEnablement
)
attributes
.
get
(
"defaultEnablement"
);
Map
<
Method
,
T
>
operations
=
discoverOperations
(
id
,
beanName
,
beanType
);
return
new
EndpointInfo
<>(
id
,
defaultEnablement
,
operations
.
values
());
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java
View file @
324a00fd
...
...
@@ -72,8 +72,8 @@ public class SecurityProperties implements SecurityPrerequisite {
/**
* Security filter chain dispatcher types.
*/
private
Set
<
DispatcherType
>
dispatcherTypes
=
new
HashSet
<>(
Arrays
.
asList
(
DispatcherType
.
ASYNC
,
DispatcherType
.
ERROR
,
DispatcherType
.
REQUEST
));
private
Set
<
DispatcherType
>
dispatcherTypes
=
new
HashSet
<>(
Arrays
.
asList
(
DispatcherType
.
ASYNC
,
DispatcherType
.
ERROR
,
DispatcherType
.
REQUEST
));
public
int
getOrder
()
{
return
this
.
order
;
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/NonUniqueSessionRepositoryException.java
View file @
324a00fd
...
...
@@ -31,17 +31,16 @@ import org.springframework.util.ObjectUtils;
*/
public
class
NonUniqueSessionRepositoryException
extends
RuntimeException
{
private
final
List
<
Class
<?
extends
SessionRepository
<?>
>>
availableCandidates
;
private
final
List
<
Class
<?>>
availableCandidates
;
public
NonUniqueSessionRepositoryException
(
List
<
Class
<?
extends
SessionRepository
<?>>>
availableCandidates
)
{
public
NonUniqueSessionRepositoryException
(
List
<
Class
<?>>
availableCandidates
)
{
super
(
"Multiple session repository candidates are available, set the "
+
"'spring.session.store-type' property accordingly"
);
this
.
availableCandidates
=
(!
ObjectUtils
.
isEmpty
(
availableCandidates
)
?
availableCandidates
:
Collections
.
emptyList
());
}
public
List
<
Class
<?
extends
SessionRepository
<?>
>>
getAvailableCandidates
()
{
public
List
<
Class
<?>>
getAvailableCandidates
()
{
return
this
.
availableCandidates
;
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/NonUniqueSessionRepositoryFailureAnalyzer.java
View file @
324a00fd
...
...
@@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.session;
import
org.springframework.boot.diagnostics.AbstractFailureAnalyzer
;
import
org.springframework.boot.diagnostics.FailureAnalysis
;
import
org.springframework.session.SessionRepository
;
/**
* A {@link AbstractFailureAnalyzer} for {@link NonUniqueSessionRepositoryException}.
...
...
@@ -34,8 +33,7 @@ class NonUniqueSessionRepositoryFailureAnalyzer
StringBuilder
message
=
new
StringBuilder
();
message
.
append
(
String
.
format
(
"Multiple Spring Session store implementations are "
+
"available on the classpath:%n"
));
for
(
Class
<?
extends
SessionRepository
<?>>
candidate
:
cause
.
getAvailableCandidates
())
{
for
(
Class
<?>
candidate
:
cause
.
getAvailableCandidates
())
{
message
.
append
(
String
.
format
(
" - %s%n"
,
candidate
.
getName
()));
}
StringBuilder
action
=
new
StringBuilder
();
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java
View file @
324a00fd
...
...
@@ -106,7 +106,7 @@ public class SessionAutoConfiguration {
@PostConstruct
public
void
checkAvailableImplementations
()
{
List
<
Class
<?
extends
SessionRepository
<?>
>>
candidates
=
new
ArrayList
<>();
List
<
Class
<?>>
candidates
=
new
ArrayList
<>();
addCandidate
(
candidates
,
"org.springframework.session.hazelcast.HazelcastSessionRepository"
);
addCandidate
(
candidates
,
...
...
@@ -119,12 +119,9 @@ public class SessionAutoConfiguration {
}
}
@SuppressWarnings
(
"unchecked"
)
private
void
addCandidate
(
List
<
Class
<?
extends
SessionRepository
<?>>>
candidates
,
String
fqn
)
{
private
void
addCandidate
(
List
<
Class
<?>>
candidates
,
String
type
)
{
try
{
Class
<?
extends
SessionRepository
<?>>
candidate
=
(
Class
<?
extends
SessionRepository
<?>>)
this
.
classLoader
.
loadClass
(
fqn
);
Class
<?>
candidate
=
this
.
classLoader
.
loadClass
(
type
);
if
(
candidate
!=
null
)
{
candidates
.
add
(
candidate
);
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java
View file @
324a00fd
...
...
@@ -52,7 +52,6 @@ public class ResourceProperties {
private
final
Chain
chain
=
new
Chain
();
public
String
[]
getStaticLocations
()
{
return
this
.
staticLocations
;
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java
View file @
324a00fd
...
...
@@ -166,7 +166,8 @@ public class WebMvcAutoConfiguration {
@Configuration
@Import
(
EnableWebMvcConfiguration
.
class
)
@EnableConfigurationProperties
({
WebMvcProperties
.
class
,
ResourceProperties
.
class
})
public
static
class
WebMvcAutoConfigurationAdapter
implements
WebMvcConfigurer
,
ResourceLoaderAware
{
public
static
class
WebMvcAutoConfigurationAdapter
implements
WebMvcConfigurer
,
ResourceLoaderAware
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
WebMvcConfigurer
.
class
);
...
...
@@ -316,8 +317,8 @@ public class WebMvcAutoConfiguration {
if
(!
registry
.
hasMappingForPattern
(
staticPathPattern
))
{
customizeResourceHandlerRegistration
(
registry
.
addResourceHandler
(
staticPathPattern
)
.
addResourceLocations
(
getResourceLocations
(
this
.
resourceProperties
.
getStaticLocations
()))
.
addResourceLocations
(
getResourceLocations
(
this
.
resourceProperties
.
getStaticLocations
()))
.
setCachePeriod
(
cachePeriod
));
}
}
...
...
@@ -329,29 +330,32 @@ public class WebMvcAutoConfiguration {
}
static
String
[]
getResourceLocations
(
String
[]
staticLocations
)
{
String
[]
locations
=
new
String
[
staticLocations
.
length
+
SERVLET_LOCATIONS
.
length
];
String
[]
locations
=
new
String
[
staticLocations
.
length
+
SERVLET_LOCATIONS
.
length
];
System
.
arraycopy
(
staticLocations
,
0
,
locations
,
0
,
staticLocations
.
length
);
System
.
arraycopy
(
SERVLET_LOCATIONS
,
0
,
locations
,
staticLocations
.
length
,
SERVLET_LOCATIONS
.
length
);
System
.
arraycopy
(
SERVLET_LOCATIONS
,
0
,
locations
,
staticLocations
.
length
,
SERVLET_LOCATIONS
.
length
);
return
locations
;
}
private
Optional
<
Resource
>
getWelcomePage
()
{
return
Arrays
.
stream
(
getResourceLocations
(
this
.
resourceProperties
.
getStaticLocations
()))
.
map
(
location
->
this
.
resourceLoader
.
getResource
(
location
+
"index.html"
))
.
filter
(
resource
->
{
try
{
if
(
resource
.
exists
())
{
resource
.
getURL
();
return
true
;
}
}
catch
(
Exception
ex
)
{
// Ignore
}
return
false
;
})
.
findFirst
();
String
[]
locations
=
getResourceLocations
(
this
.
resourceProperties
.
getStaticLocations
());
return
Arrays
.
stream
(
locations
).
map
(
this
::
getIndexHtml
)
.
filter
(
this
::
isReadable
).
findFirst
();
}
private
Resource
getIndexHtml
(
String
location
)
{
return
this
.
resourceLoader
.
getResource
(
location
+
"index.html"
);
}
private
boolean
isReadable
(
Resource
resource
)
{
try
{
return
resource
.
exists
()
&&
(
resource
.
getURL
()
!=
null
);
}
catch
(
Exception
ex
)
{
return
false
;
}
}
private
void
customizeResourceHandlerRegistration
(
...
...
@@ -359,7 +363,6 @@ public class WebMvcAutoConfiguration {
if
(
this
.
resourceHandlerRegistrationCustomizer
!=
null
)
{
this
.
resourceHandlerRegistrationCustomizer
.
customize
(
registration
);
}
}
@Bean
...
...
@@ -403,10 +406,11 @@ public class WebMvcAutoConfiguration {
}
private
List
<
Resource
>
resolveFaviconLocations
()
{
String
[]
resourceLocations
=
getResourceLocations
(
this
.
resourceProperties
.
getStaticLocations
());
List
<
Resource
>
locations
=
new
ArrayList
<>(
resourceLocations
.
length
+
1
);
Arrays
.
stream
(
resourceLocations
)
.
forEach
(
location
->
locations
.
add
(
this
.
resourceLoader
.
getResource
(
location
)));
String
[]
staticLocations
=
getResourceLocations
(
this
.
resourceProperties
.
getStaticLocations
());
List
<
Resource
>
locations
=
new
ArrayList
<>(
staticLocations
.
length
+
1
);
Arrays
.
stream
(
staticLocations
).
map
(
this
.
resourceLoader
::
getResource
)
.
forEach
(
locations:
:
add
);
locations
.
add
(
new
ClassPathResource
(
"/"
));
return
Collections
.
unmodifiableList
(
locations
);
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfigurationTests.java
View file @
324a00fd
...
...
@@ -121,8 +121,8 @@ public class OAuth2RestOperationsConfigurationTests {
}
@Configuration
@Import
({
SecurityProperties
.
class
,
OAuth2
ClientConfiguration
.
class
,
OAuth2
RestOperationsConfiguration
.
class
})
@Import
({
SecurityProperties
.
class
,
OAuth2ClientConfiguration
.
class
,
OAuth2RestOperationsConfiguration
.
class
})
protected
static
class
ConfigForSessionScopedConfiguration
extends
WebApplicationConfiguration
{
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcastTests.java
View file @
324a00fd
...
...
@@ -52,23 +52,22 @@ public class SessionAutoConfigurationHazelcastTests
@Test
public
void
defaultConfig
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.session.store-type=hazelcast"
)
this
.
contextRunner
.
withPropertyValues
(
"spring.session.store-type=hazelcast"
)
.
run
(
this
::
validateDefaultConfig
);
}
@Test
public
void
defaultConfigWithUniqueStoreImplementation
()
{
this
.
contextRunner
.
withClassLoader
(
new
HideClassesClassLoader
(
JdbcOperationsSessionRepository
.
class
,
RedisOperationsSessionRepository
.
class
)).
run
(
this
::
validateDefaultConfig
);
this
.
contextRunner
.
withClassLoader
(
new
HideClassesClassLoader
(
JdbcOperationsSessionRepository
.
class
,
RedisOperationsSessionRepository
.
class
))
.
run
(
this
::
validateDefaultConfig
);
}
private
void
validateDefaultConfig
(
AssertableWebApplicationContext
context
)
{
validateSessionRepository
(
context
,
HazelcastSessionRepository
.
class
);
HazelcastInstance
hazelcastInstance
=
context
.
getBean
(
HazelcastInstance
.
class
);
HazelcastInstance
hazelcastInstance
=
context
.
getBean
(
HazelcastInstance
.
class
);
verify
(
hazelcastInstance
,
times
(
1
)).
getMap
(
"spring:session:sessions"
);
}
...
...
@@ -95,7 +94,7 @@ public class SessionAutoConfigurationHazelcastTests
context
,
HazelcastSessionRepository
.
class
);
assertThat
(
new
DirectFieldAccessor
(
repository
)
.
getPropertyValue
(
"hazelcastFlushMode"
))
.
isEqualTo
(
HazelcastFlushMode
.
IMMEDIATE
);
.
isEqualTo
(
HazelcastFlushMode
.
IMMEDIATE
);
});
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationIntegrationTests.java
View file @
324a00fd
...
...
@@ -46,32 +46,32 @@ public class SessionAutoConfigurationIntegrationTests
SessionAutoConfiguration
.
class
))
.
withPropertyValues
(
"spring.datasource.generate-unique-name=true"
);
@Test
public
void
severalCandidatesWithNoSessionStore
()
{
this
.
contextRunner
.
withUserConfiguration
(
HazelcastConfiguration
.
class
).
run
((
context
)
->
{
assertThat
(
context
).
hasFailed
();
assertThat
(
context
).
getFailure
()
.
hasCauseInstanceOf
(
NonUniqueSessionRepositoryException
.
class
);
assertThat
(
context
).
getFailure
().
hasMessageContaining
(
"Multiple session repository candidates are available"
);
assertThat
(
context
).
getFailure
().
hasMessageContaining
(
"set the 'spring.session.store-type' property accordingly"
);
});
this
.
contextRunner
.
withUserConfiguration
(
HazelcastConfiguration
.
class
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasFailed
();
assertThat
(
context
).
getFailure
().
hasCauseInstanceOf
(
NonUniqueSessionRepositoryException
.
class
);
assertThat
(
context
).
getFailure
().
hasMessageContaining
(
"Multiple session repository candidates are available"
);
assertThat
(
context
).
getFailure
().
hasMessageContaining
(
"set the 'spring.session.store-type' property accordingly"
);
});
}
@Test
public
void
severalCandidatesWithWrongSessionStore
()
{
this
.
contextRunner
.
withUserConfiguration
(
HazelcastConfiguration
.
class
)
.
withPropertyValues
(
"spring.session.store-type=redis"
).
run
((
context
)
->
{
assertThat
(
context
).
hasFailed
();
assertThat
(
context
).
getFailure
()
.
hasCauseInstanceOf
(
SessionRepositoryUnavailableException
.
class
);
assertThat
(
context
).
getFailure
().
hasMessageContaining
(
"No session repository could be auto-configured"
);
assertThat
(
context
).
getFailure
().
hasMessageContaining
(
"session store type is 'redis'"
);
});
assertThat
(
context
).
hasFailed
();
assertThat
(
context
).
getFailure
().
hasCauseInstanceOf
(
SessionRepositoryUnavailableException
.
class
);
assertThat
(
context
).
getFailure
().
hasMessageContaining
(
"No session repository could be auto-configured"
);
assertThat
(
context
).
getFailure
()
.
hasMessageContaining
(
"session store type is 'redis'"
);
});
}
@Test
...
...
@@ -82,7 +82,6 @@ public class SessionAutoConfigurationIntegrationTests
JdbcOperationsSessionRepository
.
class
));
}
@Configuration
static
class
HazelcastConfiguration
{
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationJdbcTests.java
View file @
324a00fd
...
...
@@ -58,8 +58,7 @@ public class SessionAutoConfigurationJdbcTests
@Test
public
void
defaultConfig
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.session.store-type=jdbc"
)
this
.
contextRunner
.
withPropertyValues
(
"spring.session.store-type=jdbc"
)
.
withConfiguration
(
AutoConfigurations
.
of
(
JdbcTemplateAutoConfiguration
.
class
))
.
run
(
this
::
validateDefaultConfig
);
...
...
@@ -68,22 +67,20 @@ public class SessionAutoConfigurationJdbcTests
@Test
public
void
defaultConfigWithUniqueStoreImplementation
()
{
this
.
contextRunner
.
withClassLoader
(
new
HideClassesClassLoader
(
HazelcastSessionRepository
.
class
,
RedisOperationsSessionRepository
.
class
)
)
.
withClassLoader
(
new
HideClassesClassLoader
(
HazelcastSessionRepository
.
class
,
RedisOperationsSessionRepository
.
class
))
.
withConfiguration
(
AutoConfigurations
.
of
(
JdbcTemplateAutoConfiguration
.
class
))
.
run
(
this
::
validateDefaultConfig
);
}
private
void
validateDefaultConfig
(
AssertableWebApplicationContext
context
)
{
JdbcOperationsSessionRepository
repository
=
validateSessionRepository
(
context
,
JdbcOperationsSessionRepository
.
class
);
assertThat
(
new
DirectFieldAccessor
(
repository
)
.
getPropertyValue
(
"tableName"
)).
isEqualTo
(
"SPRING_SESSION"
);
assertThat
(
context
.
getBean
(
JdbcSessionProperties
.
class
)
.
getInitializeSchema
())
JdbcOperationsSessionRepository
repository
=
validateSessionRepository
(
context
,
JdbcOperationsSessionRepository
.
class
);
assertThat
(
new
DirectFieldAccessor
(
repository
).
getPropertyValue
(
"tableName"
))
.
isEqualTo
(
"SPRING_SESSION"
);
assertThat
(
context
.
getBean
(
JdbcSessionProperties
.
class
).
getInitializeSchema
())
.
isEqualTo
(
DatabaseInitializationMode
.
EMBEDDED
);
assertThat
(
context
.
getBean
(
JdbcOperations
.
class
)
.
queryForList
(
"select * from SPRING_SESSION"
)).
isEmpty
();
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationRedisTests.java
View file @
324a00fd
...
...
@@ -50,8 +50,7 @@ public class SessionAutoConfigurationRedisTests
@Test
public
void
defaultConfig
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.session.store-type=redis"
)
this
.
contextRunner
.
withPropertyValues
(
"spring.session.store-type=redis"
)
.
withConfiguration
(
AutoConfigurations
.
of
(
RedisAutoConfiguration
.
class
))
.
run
(
validateSpringSessionUsesRedis
(
"spring:session:event:created:"
,
RedisFlushMode
.
ON_SAVE
));
...
...
@@ -60,9 +59,9 @@ public class SessionAutoConfigurationRedisTests
@Test
public
void
defaultConfigWithUniqueStoreImplementation
()
{
this
.
contextRunner
.
withClassLoader
(
new
HideClassesClassLoader
(
HazelcastSessionRepository
.
class
,
JdbcOperationsSessionRepository
.
class
))
.
withClassLoader
(
new
HideClassesClassLoader
(
HazelcastSessionRepository
.
class
,
JdbcOperationsSessionRepository
.
class
))
.
withConfiguration
(
AutoConfigurations
.
of
(
RedisAutoConfiguration
.
class
))
.
run
(
validateSpringSessionUsesRedis
(
"spring:session:event:created:"
,
RedisFlushMode
.
ON_SAVE
));
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationTests.java
View file @
324a00fd
...
...
@@ -66,12 +66,12 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
this
.
contextRunner
.
withPropertyValues
(
"spring.session.store-type=jdbc"
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasFailed
();
assertThat
(
context
).
getFailure
()
.
hasCauseInstanceOf
(
SessionRepositoryUnavailableException
.
class
);
assertThat
(
context
).
getFailure
()
.
hasCauseInstanceOf
(
SessionRepositoryUnavailableException
.
class
);
assertThat
(
context
).
getFailure
().
hasMessageContaining
(
"No session repository could be auto-configured"
);
assertThat
(
context
).
getFailure
()
.
hasMessageContaining
(
"session store type is 'jdbc'"
);
assertThat
(
context
).
getFailure
()
.
hasMessageContaining
(
"session store type is 'jdbc'"
);
});
}
...
...
@@ -86,18 +86,17 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
public
void
backOffIfSessionRepositoryIsPresent
()
{
this
.
contextRunner
.
withUserConfiguration
(
SessionRepositoryConfiguration
.
class
)
.
withPropertyValues
(
"spring.session.store-type=redis"
).
run
((
context
)
->
{
MapSessionRepository
repository
=
validateSessionRepository
(
context
,
MapSessionRepository
.
class
);
assertThat
(
context
).
getBean
(
"mySessionRepository"
)
.
isSameAs
(
repository
);
});
MapSessionRepository
repository
=
validateSessionRepository
(
context
,
MapSessionRepository
.
class
);
assertThat
(
context
).
getBean
(
"mySessionRepository"
)
.
isSameAs
(
repository
);
});
}
@Test
public
void
springSessionTimeoutIsNotAValidProperty
()
{
this
.
contextRunner
.
withUserConfiguration
(
SessionRepositoryConfiguration
.
class
)
.
withPropertyValues
(
"spring.session.timeout=3000"
)
.
run
((
context
)
->
{
.
withPropertyValues
(
"spring.session.timeout=3000"
).
run
((
context
)
->
{
assertThat
(
context
).
hasFailed
();
assertThat
(
context
).
getFailure
()
.
isInstanceOf
(
BeanCreationException
.
class
);
...
...
spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java
View file @
324a00fd
...
...
@@ -367,8 +367,8 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
if
(
endpointId
==
null
||
""
.
equals
(
endpointId
))
{
return
;
// Can't process that endpoint
}
Boolean
enabledByDefault
=
determineEnabledByDefault
(
elementValues
.
get
(
"defaultEnablement"
));
Boolean
enabledByDefault
=
determineEnabledByDefault
(
elementValues
.
get
(
"defaultEnablement"
));
String
type
=
this
.
typeUtils
.
getQualifiedName
(
element
);
this
.
metadataCollector
.
add
(
ItemMetadata
.
newGroup
(
endpointKey
(
endpointId
),
type
,
type
,
null
));
...
...
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java
View file @
324a00fd
...
...
@@ -123,9 +123,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
.
withDescription
(
"The name of this simple properties."
)
.
withDefaultValue
(
"boot"
).
withDeprecation
(
null
,
null
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"simple.flag"
,
Boolean
.
class
)
.
withDefaultValue
(
false
)
.
fromSource
(
SimpleProperties
.
class
).
withDescription
(
"A simple flag."
)
.
withDeprecation
(
null
,
null
));
.
withDefaultValue
(
false
).
fromSource
(
SimpleProperties
.
class
)
.
withDescription
(
"A simple flag."
).
withDeprecation
(
null
,
null
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"simple.comparator"
));
assertThat
(
metadata
).
doesNotHave
(
Metadata
.
withProperty
(
"simple.counter"
));
assertThat
(
metadata
).
doesNotHave
(
Metadata
.
withProperty
(
"simple.size"
));
...
...
@@ -163,8 +162,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
.
withDefaultValue
(
false
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"simple.type.my-short"
,
Short
.
class
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"simple.type.my-primitive-short"
,
Short
.
class
)
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"simple.type.my-primitive-short"
,
Short
.
class
)
.
withDefaultValue
(
0
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"simple.type.my-integer"
,
Integer
.
class
));
...
...
@@ -245,9 +244,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
Class
<?>
type
=
BoxingPojo
.
class
;
ConfigurationMetadata
metadata
=
compile
(
type
);
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"boxing"
).
fromSource
(
type
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"boxing.flag"
,
Boolean
.
class
)
.
withDefaultValue
(
false
).
fromSource
(
type
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"boxing.flag"
,
Boolean
.
class
)
.
withDefaultValue
(
false
).
fromSource
(
type
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"boxing.counter"
,
Integer
.
class
).
fromSource
(
type
));
}
...
...
@@ -316,8 +314,7 @@ public class ConfigurationMetadataAnnotationProcessorTests {
.
fromSource
(
DeprecatedMethodConfig
.
Foo
.
class
)
.
withDeprecation
(
null
,
null
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.flag"
,
Boolean
.
class
)
.
withDefaultValue
(
false
)
.
fromSource
(
DeprecatedMethodConfig
.
Foo
.
class
)
.
withDefaultValue
(
false
).
fromSource
(
DeprecatedMethodConfig
.
Foo
.
class
)
.
withDeprecation
(
null
,
null
));
}
...
...
@@ -331,10 +328,10 @@ public class ConfigurationMetadataAnnotationProcessorTests {
.
fromSource
(
org
.
springframework
.
boot
.
configurationsample
.
method
.
DeprecatedClassMethodConfig
.
Foo
.
class
)
.
withDeprecation
(
null
,
null
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.flag"
,
Boolean
.
class
)
.
withDefaultValue
(
false
)
.
fromSource
(
org
.
springframework
.
boot
.
configurationsample
.
method
.
DeprecatedClassMethodConfig
.
Foo
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.flag"
,
Boolean
.
class
)
.
withDefaultValue
(
false
)
.
fromSource
(
org
.
springframework
.
boot
.
configurationsample
.
method
.
DeprecatedClassMethodConfig
.
Foo
.
class
)
.
withDeprecation
(
null
,
null
));
}
...
...
@@ -879,34 +876,30 @@ public class ConfigurationMetadataAnnotationProcessorTests {
assertThat
(
project
.
getOutputFile
(
MetadataStore
.
METADATA_PATH
).
exists
()).
isFalse
();
ConfigurationMetadata
metadata
=
project
.
fullBuild
();
assertThat
(
project
.
getOutputFile
(
MetadataStore
.
METADATA_PATH
).
exists
()).
isTrue
();
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.counter"
).
fromSource
(
FooProperties
.
class
)
.
withDefaultValue
(
0
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"bar.counter"
).
fromSource
(
BarProperties
.
class
)
.
withDefaultValue
(
0
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.counter"
)
.
fromSource
(
FooProperties
.
class
).
withDefaultValue
(
0
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"bar.counter"
)
.
fromSource
(
BarProperties
.
class
).
withDefaultValue
(
0
));
metadata
=
project
.
incrementalBuild
(
BarProperties
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.counter"
).
fromSource
(
FooProperties
.
class
)
.
withDefaultValue
(
0
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"bar.counter"
).
fromSource
(
BarProperties
.
class
)
.
withDefaultValue
(
0
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.counter"
)
.
fromSource
(
FooProperties
.
class
).
withDefaultValue
(
0
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"bar.counter"
)
.
fromSource
(
BarProperties
.
class
).
withDefaultValue
(
0
));
project
.
addSourceCode
(
BarProperties
.
class
,
BarProperties
.
class
.
getResourceAsStream
(
"BarProperties.snippet"
));
metadata
=
project
.
incrementalBuild
(
BarProperties
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"bar.extra"
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"foo.counter"
)
.
withDefaultValue
(
0
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"bar.counter"
)
.
withDefaultValue
(
0
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"foo.counter"
).
withDefaultValue
(
0
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"bar.counter"
).
withDefaultValue
(
0
));
project
.
revert
(
BarProperties
.
class
);
metadata
=
project
.
incrementalBuild
(
BarProperties
.
class
);
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withProperty
(
"bar.extra"
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"foo.counter"
)
.
withDefaultValue
(
0
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"bar.counter"
)
.
withDefaultValue
(
0
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"foo.counter"
).
withDefaultValue
(
0
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"bar.counter"
).
withDefaultValue
(
0
));
}
@Test
...
...
@@ -914,15 +907,15 @@ public class ConfigurationMetadataAnnotationProcessorTests {
TestProject
project
=
new
TestProject
(
this
.
temporaryFolder
,
FooProperties
.
class
,
BarProperties
.
class
);
ConfigurationMetadata
metadata
=
project
.
fullBuild
();
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"foo.counter"
)
.
withDefaultValue
(
0
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"bar.counter"
)
.
withDefaultValue
(
0
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"foo.counter"
).
withDefaultValue
(
0
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"bar.counter"
).
withDefaultValue
(
0
));
project
.
replaceText
(
BarProperties
.
class
,
"@ConfigurationProperties"
,
"//@ConfigurationProperties"
);
metadata
=
project
.
incrementalBuild
(
BarProperties
.
class
);
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"foo.counter"
)
.
withDefaultValue
(
0
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"foo.counter"
).
withDefaultValue
(
0
));
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withProperty
(
"bar.counter"
));
}
...
...
@@ -931,25 +924,21 @@ public class ConfigurationMetadataAnnotationProcessorTests {
TestProject
project
=
new
TestProject
(
this
.
temporaryFolder
,
FooProperties
.
class
,
BarProperties
.
class
);
ConfigurationMetadata
metadata
=
project
.
fullBuild
();
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.counter"
).
fromSource
(
FooProperties
.
class
)
.
withDefaultValue
(
0
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"bar.counter"
).
fromSource
(
BarProperties
.
class
)
.
withDefaultValue
(
0
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.counter"
)
.
fromSource
(
FooProperties
.
class
).
withDefaultValue
(
0
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"bar.counter"
)
.
fromSource
(
BarProperties
.
class
).
withDefaultValue
(
0
));
assertThat
(
metadata
).
doesNotHave
(
Metadata
.
withProperty
(
"bar.counter"
)
.
fromSource
(
RenamedBarProperties
.
class
));
project
.
delete
(
BarProperties
.
class
);
project
.
add
(
RenamedBarProperties
.
class
);
metadata
=
project
.
incrementalBuild
(
RenamedBarProperties
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.counter"
).
fromSource
(
FooProperties
.
class
)
.
withDefaultValue
(
0
));
assertThat
(
metadata
).
doesNotHave
(
Metadata
.
withProperty
(
"bar.counter"
).
fromSource
(
BarProperties
.
class
)
.
withDefaultValue
(
0
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"bar.counter"
)
.
withDefaultValue
(
0
).
fromSource
(
RenamedBarProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.counter"
)
.
fromSource
(
FooProperties
.
class
).
withDefaultValue
(
0
));
assertThat
(
metadata
).
doesNotHave
(
Metadata
.
withProperty
(
"bar.counter"
)
.
fromSource
(
BarProperties
.
class
).
withDefaultValue
(
0
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"bar.counter"
).
withDefaultValue
(
0
)
.
fromSource
(
RenamedBarProperties
.
class
));
}
private
void
assertSimpleLombokProperties
(
ConfigurationMetadata
metadata
,
...
...
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/DefaultEnablement.java
View file @
324a00fd
...
...
@@ -19,4 +19,5 @@ package org.springframework.boot.configurationsample;
public
enum
DefaultEnablement
{
ENABLED
,
DISABLED
,
NEUTRAL
}
spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinderBuilder.java
View file @
324a00fd
...
...
@@ -29,6 +29,7 @@ import org.springframework.core.convert.converter.GenericConverter;
import
org.springframework.core.convert.support.DefaultConversionService
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.PropertySource
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.validation.Validator
;
...
...
@@ -67,6 +68,7 @@ public class ConfigurationPropertiesBinderBuilder {
* @param applicationContext the application context
*/
public
ConfigurationPropertiesBinderBuilder
(
ApplicationContext
applicationContext
)
{
Assert
.
notNull
(
applicationContext
,
"ApplicationContext must not be null"
);
this
.
applicationContext
=
applicationContext
;
}
...
...
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