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
7942d9f7
Commit
7942d9f7
authored
Mar 22, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
2ae14359
Changes
61
Hide whitespace changes
Inline
Side-by-side
Showing
61 changed files
with
494 additions
and
343 deletions
+494
-343
InfoContributorAutoConfiguration.java
...tuate/autoconfigure/InfoContributorAutoConfiguration.java
+2
-1
BuildInfoContributor.java
...ringframework/boot/actuate/info/BuildInfoContributor.java
+0
-1
GitInfoContributor.java
...springframework/boot/actuate/info/GitInfoContributor.java
+5
-2
InfoPropertiesInfoContributor.java
...work/boot/actuate/info/InfoPropertiesInfoContributor.java
+6
-10
EndpointAutoConfigurationTests.java
...actuate/autoconfigure/EndpointAutoConfigurationTests.java
+4
-3
InfoContributorAutoConfigurationTests.java
.../autoconfigure/InfoContributorAutoConfigurationTests.java
+8
-8
SpringApplicationHierarchyTests.java
...ctuate/autoconfigure/SpringApplicationHierarchyTests.java
+5
-5
GitInfoContributorTests.java
...gframework/boot/actuate/info/GitInfoContributorTests.java
+4
-2
RabbitAutoConfiguration.java
...work/boot/autoconfigure/amqp/RabbitAutoConfiguration.java
+21
-20
RabbitProperties.java
...ngframework/boot/autoconfigure/amqp/RabbitProperties.java
+1
-2
SimpleRabbitListenerContainerFactoryConfigurer.java
.../amqp/SimpleRabbitListenerContainerFactoryConfigurer.java
+8
-8
CacheAutoConfiguration.java
...work/boot/autoconfigure/cache/CacheAutoConfiguration.java
+1
-1
CacheConfigurations.java
...amework/boot/autoconfigure/cache/CacheConfigurations.java
+3
-3
CouchbaseCacheConfiguration.java
...boot/autoconfigure/cache/CouchbaseCacheConfiguration.java
+3
-3
CouchbaseAutoConfiguration.java
...t/autoconfigure/couchbase/CouchbaseAutoConfiguration.java
+10
-10
CouchbaseProperties.java
...ork/boot/autoconfigure/couchbase/CouchbaseProperties.java
+2
-2
CouchbaseConfigurerAdapterConfiguration.java
...ta/couchbase/CouchbaseConfigurerAdapterConfiguration.java
+6
-4
CouchbaseDataAutoConfiguration.java
...figure/data/couchbase/CouchbaseDataAutoConfiguration.java
+1
-1
CouchbaseRepositoriesRegistrar.java
...figure/data/couchbase/CouchbaseRepositoriesRegistrar.java
+0
-1
SpringBootCouchbaseDataConfiguration.java
.../data/couchbase/SpringBootCouchbaseDataConfiguration.java
+1
-3
RedisRepositoriesAutoConfiguration.java
...figure/data/redis/RedisRepositoriesAutoConfiguration.java
+1
-0
RedisRepositoriesAutoConfigureRegistrar.java
...e/data/redis/RedisRepositoriesAutoConfigureRegistrar.java
+1
-0
H2ConsoleAutoConfiguration.java
...ork/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.java
+2
-1
ProjectInfoAutoConfiguration.java
...boot/autoconfigure/info/ProjectInfoAutoConfiguration.java
+6
-3
ProjectInfoProperties.java
...mework/boot/autoconfigure/info/ProjectInfoProperties.java
+2
-2
JmsAutoConfiguration.java
...ramework/boot/autoconfigure/jms/JmsAutoConfiguration.java
+2
-1
ActiveMQConnectionFactoryConfiguration.java
.../jms/activemq/ActiveMQConnectionFactoryConfiguration.java
+2
-1
ActiveMQProperties.java
...k/boot/autoconfigure/jms/activemq/ActiveMQProperties.java
+22
-1
ActiveMQXAConnectionFactoryConfiguration.java
...ms/activemq/ActiveMQXAConnectionFactoryConfiguration.java
+1
-1
RabbitAutoConfigurationTests.java
...boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java
+17
-9
CacheAutoConfigurationTests.java
...boot/autoconfigure/cache/CacheAutoConfigurationTests.java
+14
-7
AbstractCouchbaseAutoConfigurationTests.java
...re/couchbase/AbstractCouchbaseAutoConfigurationTests.java
+2
-0
CouchbaseAutoConfigurationIntegrationTests.java
...couchbase/CouchbaseAutoConfigurationIntegrationTests.java
+0
-1
CouchbaseAutoConfigurationTests.java
...oconfigure/couchbase/CouchbaseAutoConfigurationTests.java
+8
-8
CouchbaseTestServer.java
...ork/boot/autoconfigure/couchbase/CouchbaseTestServer.java
+23
-19
CouchbaseDataAutoConfigurationTests.java
...e/data/couchbase/CouchbaseDataAutoConfigurationTests.java
+7
-8
CouchbaseRepositoriesAutoConfigurationTests.java
...ouchbase/CouchbaseRepositoriesAutoConfigurationTests.java
+1
-2
RedisRepositoriesAutoConfigurationTests.java
...e/data/redis/RedisRepositoriesAutoConfigurationTests.java
+5
-8
H2ConsoleAutoConfigurationTests.java
...oot/autoconfigure/h2/H2ConsoleAutoConfigurationTests.java
+13
-14
ProjectInfoAutoConfigurationTests.java
...autoconfigure/info/ProjectInfoAutoConfigurationTests.java
+10
-5
ActiveMQAutoConfigurationTests.java
...onfigure/jms/activemq/ActiveMQAutoConfigurationTests.java
+13
-12
ActiveMQPropertiesTests.java
...t/autoconfigure/jms/activemq/ActiveMQPropertiesTests.java
+1
-1
spring-boot-features.adoc
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+4
-0
BuildInfoMojo.java
...in/java/org/springframework/boot/maven/BuildInfoMojo.java
+22
-16
Verify.java
.../src/test/java/org/springframework/boot/maven/Verify.java
+0
-1
PropertySourcesBinder.java
.../org/springframework/boot/bind/PropertySourcesBinder.java
+3
-3
ConfigurationProperties.java
...work/boot/context/properties/ConfigurationProperties.java
+4
-2
LocalServerPort.java
...org/springframework/boot/context/web/LocalServerPort.java
+8
-6
ServerPortInfoApplicationContextInitializer.java
...text/web/ServerPortInfoApplicationContextInitializer.java
+18
-17
BuildProperties.java
...n/java/org/springframework/boot/info/BuildProperties.java
+2
-2
GitProperties.java
...ain/java/org/springframework/boot/info/GitProperties.java
+14
-12
InfoProperties.java
...in/java/org/springframework/boot/info/InfoProperties.java
+36
-41
LoggingApplicationListener.java
...ingframework/boot/logging/LoggingApplicationListener.java
+4
-5
PropertySourcesBinderTests.java
...springframework/boot/bind/PropertySourcesBinderTests.java
+6
-3
LocalServerPortTests.java
...pringframework/boot/context/web/LocalServerPortTests.java
+55
-0
BuildPropertiesTests.java
...a/org/springframework/boot/info/BuildPropertiesTests.java
+2
-2
GitPropertiesTests.java
...ava/org/springframework/boot/info/GitPropertiesTests.java
+2
-1
InfoPropertiesTests.java
...va/org/springframework/boot/info/InfoPropertiesTests.java
+1
-0
ClassPathExclusions.java
...rg/springframework/boot/testutil/ClassPathExclusions.java
+0
-1
FilteredClassPathRunner.java
...pringframework/boot/testutil/FilteredClassPathRunner.java
+64
-32
FilteredClassPathRunnerTests.java
...framework/boot/testutil/FilteredClassPathRunnerTests.java
+5
-5
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/InfoContributorAutoConfiguration.java
View file @
7942d9f7
...
...
@@ -82,7 +82,8 @@ public class InfoContributorAutoConfiguration {
@ConditionalOnSingleCandidate
(
BuildProperties
.
class
)
@Order
(
DEFAULT_ORDER
)
public
InfoContributor
buildInfoContributor
(
BuildProperties
buildProperties
)
{
return
new
BuildInfoContributor
(
buildProperties
,
this
.
properties
.
getBuild
().
getMode
());
return
new
BuildInfoContributor
(
buildProperties
,
this
.
properties
.
getBuild
().
getMode
());
}
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/BuildInfoContributor.java
View file @
7942d9f7
...
...
@@ -23,7 +23,6 @@ import org.springframework.boot.info.BuildProperties;
import
org.springframework.core.env.PropertiesPropertySource
;
import
org.springframework.core.env.PropertySource
;
/**
* An {@link InfoContributor} that exposes {@link BuildProperties}.
*
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/GitInfoContributor.java
View file @
7942d9f7
...
...
@@ -62,9 +62,12 @@ public class GitInfoContributor extends InfoPropertiesInfoContributor<GitPropert
* are converted to {@link Date} instances.
* @param content the content to expose
*/
@Override
protected
void
postProcessContent
(
Map
<
String
,
Object
>
content
)
{
replaceValue
(
getNestedMap
(
content
,
"commit"
),
"time"
,
getProperties
().
getCommitTime
());
replaceValue
(
getNestedMap
(
content
,
"build"
),
"time"
,
getProperties
().
getDate
(
"build.time"
));
replaceValue
(
getNestedMap
(
content
,
"commit"
),
"time"
,
getProperties
().
getCommitTime
());
replaceValue
(
getNestedMap
(
content
,
"build"
),
"time"
,
getProperties
().
getDate
(
"build.time"
));
}
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/InfoPropertiesInfoContributor.java
View file @
7942d9f7
...
...
@@ -32,7 +32,8 @@ import org.springframework.util.StringUtils;
* @author Stephane Nicoll
* @since 1.4.0
*/
public
abstract
class
InfoPropertiesInfoContributor
<
T
extends
InfoProperties
>
implements
InfoContributor
{
public
abstract
class
InfoPropertiesInfoContributor
<
T
extends
InfoProperties
>
implements
InfoContributor
{
private
final
T
properties
;
...
...
@@ -103,9 +104,7 @@ public abstract class InfoPropertiesInfoContributor<T extends InfoProperties> im
if
(
this
.
mode
.
equals
(
Mode
.
FULL
))
{
return
this
.
properties
.
toPropertySource
();
}
else
{
return
toSimplePropertySource
();
}
return
toSimplePropertySource
();
}
/**
...
...
@@ -141,16 +140,13 @@ public abstract class InfoPropertiesInfoContributor<T extends InfoProperties> im
*/
@SuppressWarnings
(
"unchecked"
)
protected
Map
<
String
,
Object
>
getNestedMap
(
Map
<
String
,
Object
>
map
,
String
key
)
{
Object
o
=
map
.
get
(
key
);
if
(
o
==
null
)
{
Object
value
=
map
.
get
(
key
);
if
(
value
==
null
)
{
return
Collections
.
emptyMap
();
}
else
{
return
(
Map
<
String
,
Object
>)
o
;
}
return
(
Map
<
String
,
Object
>)
value
;
}
/**
* Defines how properties should be exposed.
*/
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfigurationTests.java
View file @
7942d9f7
...
...
@@ -269,9 +269,10 @@ public class EndpointAutoConfigurationTests {
if
(
location
.
exists
())
{
Properties
gitInfoProperties
=
PropertiesLoaderUtils
.
loadProperties
(
location
);
PropertiesPropertySource
gitPropertySource
=
new
PropertiesPropertySource
(
"git"
,
gitInfoProperties
);
this
.
content
=
new
PropertySourcesBinder
(
gitPropertySource
).
extractAll
(
"git"
);
PropertiesPropertySource
gitPropertySource
=
new
PropertiesPropertySource
(
"git"
,
gitInfoProperties
);
this
.
content
=
new
PropertySourcesBinder
(
gitPropertySource
)
.
extractAll
(
"git"
);
}
}
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/InfoContributorAutoConfigurationTests.java
View file @
7942d9f7
...
...
@@ -85,8 +85,8 @@ public class InfoContributorAutoConfigurationTests {
Map
<
String
,
InfoContributor
>
beans
=
this
.
context
.
getBeansOfType
(
InfoContributor
.
class
);
assertThat
(
beans
).
containsKeys
(
"gitInfoContributor"
);
Map
<
String
,
Object
>
content
=
invokeContributor
(
this
.
context
.
getBean
(
"gitInfoContributor"
,
InfoContributor
.
class
));
Map
<
String
,
Object
>
content
=
invokeContributor
(
this
.
context
.
getBean
(
"gitInfoContributor"
,
InfoContributor
.
class
));
Object
git
=
content
.
get
(
"git"
);
assertThat
(
git
).
isInstanceOf
(
Map
.
class
);
Map
<
String
,
Object
>
gitInfo
=
(
Map
<
String
,
Object
>)
git
;
...
...
@@ -97,8 +97,8 @@ public class InfoContributorAutoConfigurationTests {
@Test
public
void
gitPropertiesFullMode
()
{
load
(
GitPropertiesConfiguration
.
class
,
"management.info.git.mode=full"
);
Map
<
String
,
Object
>
content
=
invokeContributor
(
this
.
context
.
getBean
(
"gitInfoContributor"
,
InfoContributor
.
class
));
Map
<
String
,
Object
>
content
=
invokeContributor
(
this
.
context
.
getBean
(
"gitInfoContributor"
,
InfoContributor
.
class
));
Object
git
=
content
.
get
(
"git"
);
assertThat
(
git
).
isInstanceOf
(
Map
.
class
);
Map
<
String
,
Object
>
gitInfo
=
(
Map
<
String
,
Object
>)
git
;
...
...
@@ -120,8 +120,8 @@ public class InfoContributorAutoConfigurationTests {
Map
<
String
,
InfoContributor
>
beans
=
this
.
context
.
getBeansOfType
(
InfoContributor
.
class
);
assertThat
(
beans
).
containsKeys
(
"buildInfoContributor"
);
Map
<
String
,
Object
>
content
=
invokeContributor
(
this
.
context
.
getBean
(
"buildInfoContributor"
,
InfoContributor
.
class
));
Map
<
String
,
Object
>
content
=
invokeContributor
(
this
.
context
.
getBean
(
"buildInfoContributor"
,
InfoContributor
.
class
));
Object
build
=
content
.
get
(
"build"
);
assertThat
(
build
).
isInstanceOf
(
Map
.
class
);
Map
<
String
,
Object
>
gitInfo
=
(
Map
<
String
,
Object
>)
build
;
...
...
@@ -132,8 +132,8 @@ public class InfoContributorAutoConfigurationTests {
@Test
public
void
buildPropertiesFullMode
()
{
load
(
BuildPropertiesConfiguration
.
class
,
"management.info.build.mode=full"
);
Map
<
String
,
Object
>
content
=
invokeContributor
(
this
.
context
.
getBean
(
"buildInfoContributor"
,
InfoContributor
.
class
));
Map
<
String
,
Object
>
content
=
invokeContributor
(
this
.
context
.
getBean
(
"buildInfoContributor"
,
InfoContributor
.
class
));
Object
build
=
content
.
get
(
"build"
);
assertThat
(
build
).
isInstanceOf
(
Map
.
class
);
Map
<
String
,
Object
>
gitInfo
=
(
Map
<
String
,
Object
>)
build
;
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/SpringApplicationHierarchyTests.java
View file @
7942d9f7
...
...
@@ -62,24 +62,24 @@ public class SpringApplicationHierarchyTests {
@EnableAutoConfiguration
(
exclude
=
{
ElasticsearchDataAutoConfiguration
.
class
,
ElasticsearchRepositoriesAutoConfiguration
.
class
,
CassandraAutoConfiguration
.
class
,
CassandraDataAutoConfiguration
.
class
,
CassandraAutoConfiguration
.
class
,
CassandraDataAutoConfiguration
.
class
,
RedisAutoConfiguration
.
class
,
RedisRepositoriesAutoConfiguration
.
class
},
excludeName
=
{
RedisRepositoriesAutoConfiguration
.
class
},
excludeName
=
{
"org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration"
})
public
static
class
Child
{
}
@EnableAutoConfiguration
(
exclude
=
{
JolokiaAutoConfiguration
.
class
,
EndpointMBeanExportAutoConfiguration
.
class
,
ElasticsearchDataAutoConfiguration
.
class
,
ElasticsearchRepositoriesAutoConfiguration
.
class
,
CassandraAutoConfiguration
.
class
,
CassandraDataAutoConfiguration
.
class
,
CassandraAutoConfiguration
.
class
,
CassandraDataAutoConfiguration
.
class
,
RedisAutoConfiguration
.
class
,
RedisRepositoriesAutoConfiguration
.
class
},
excludeName
=
{
"org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration"
})
public
static
class
Parent
{
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/GitInfoContributorTests.java
View file @
7942d9f7
...
...
@@ -39,7 +39,8 @@ public class GitInfoContributorTests {
Properties
properties
=
new
Properties
();
properties
.
put
(
"branch"
,
"master"
);
properties
.
put
(
"commit.time"
,
"2016-03-04T14:36:33+0100"
);
GitInfoContributor
contributor
=
new
GitInfoContributor
(
new
GitProperties
(
properties
));
GitInfoContributor
contributor
=
new
GitInfoContributor
(
new
GitProperties
(
properties
));
Map
<
String
,
Object
>
content
=
contributor
.
generateContent
();
assertThat
(
content
.
get
(
"commit"
)).
isInstanceOf
(
Map
.
class
);
Map
<
String
,
Object
>
commit
=
(
Map
<
String
,
Object
>)
content
.
get
(
"commit"
);
...
...
@@ -54,7 +55,8 @@ public class GitInfoContributorTests {
Properties
properties
=
new
Properties
();
properties
.
put
(
"branch"
,
"master"
);
properties
.
put
(
"commit.id"
,
"8e29a0b0d423d2665c6ee5171947c101a5c15681"
);
GitInfoContributor
contributor
=
new
GitInfoContributor
(
new
GitProperties
(
properties
));
GitInfoContributor
contributor
=
new
GitInfoContributor
(
new
GitProperties
(
properties
));
Map
<
String
,
Object
>
content
=
contributor
.
generateContent
();
assertThat
(
content
.
get
(
"commit"
)).
isInstanceOf
(
Map
.
class
);
Map
<
String
,
Object
>
commit
=
(
Map
<
String
,
Object
>)
content
.
get
(
"commit"
);
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java
View file @
7942d9f7
...
...
@@ -29,8 +29,6 @@ import org.springframework.amqp.support.converter.MessageConverter;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.amqp.RabbitProperties.Retry
;
import
org.springframework.boot.autoconfigure.amqp.RabbitProperties.Template
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
...
...
@@ -161,29 +159,33 @@ public class RabbitAutoConfiguration {
if
(
messageConverter
!=
null
)
{
rabbitTemplate
.
setMessageConverter
(
messageConverter
);
}
Template
template
=
this
.
properties
.
getTemplate
();
Retry
retry
=
template
.
getRetry
();
if
(
retry
.
isEnabled
())
{
RetryTemplate
retryTemplate
=
new
RetryTemplate
();
SimpleRetryPolicy
retryPolicy
=
new
SimpleRetryPolicy
();
retryPolicy
.
setMaxAttempts
(
retry
.
getMaxAttempts
());
retryTemplate
.
setRetryPolicy
(
retryPolicy
);
ExponentialBackOffPolicy
backOffPolicy
=
new
ExponentialBackOffPolicy
();
backOffPolicy
.
setInitialInterval
(
retry
.
getInitialInterval
());
backOffPolicy
.
setMultiplier
(
retry
.
getMultiplier
());
backOffPolicy
.
setMaxInterval
(
retry
.
getMaxInterval
());
retryTemplate
.
setBackOffPolicy
(
backOffPolicy
);
rabbitTemplate
.
setRetryTemplate
(
retryTemplate
);
RabbitProperties
.
Template
templateProperties
=
this
.
properties
.
getTemplate
();
RabbitProperties
.
Retry
retryProperties
=
templateProperties
.
getRetry
();
if
(
retryProperties
.
isEnabled
())
{
rabbitTemplate
.
setRetryTemplate
(
createRetryTemplate
(
retryProperties
));
}
if
(
template
.
getReceiveTimeout
()
!=
null
)
{
rabbitTemplate
.
setReceiveTimeout
(
template
.
getReceiveTimeout
());
if
(
template
Properties
.
getReceiveTimeout
()
!=
null
)
{
rabbitTemplate
.
setReceiveTimeout
(
template
Properties
.
getReceiveTimeout
());
}
if
(
template
.
getReplyTimeout
()
!=
null
)
{
rabbitTemplate
.
setReplyTimeout
(
template
.
getReplyTimeout
());
if
(
template
Properties
.
getReplyTimeout
()
!=
null
)
{
rabbitTemplate
.
setReplyTimeout
(
template
Properties
.
getReplyTimeout
());
}
return
rabbitTemplate
;
}
private
RetryTemplate
createRetryTemplate
(
RabbitProperties
.
Retry
properties
)
{
RetryTemplate
template
=
new
RetryTemplate
();
SimpleRetryPolicy
policy
=
new
SimpleRetryPolicy
();
policy
.
setMaxAttempts
(
properties
.
getMaxAttempts
());
template
.
setRetryPolicy
(
policy
);
ExponentialBackOffPolicy
backOffPolicy
=
new
ExponentialBackOffPolicy
();
backOffPolicy
.
setInitialInterval
(
properties
.
getInitialInterval
());
backOffPolicy
.
setMultiplier
(
properties
.
getMultiplier
());
backOffPolicy
.
setMaxInterval
(
properties
.
getMaxInterval
());
template
.
setBackOffPolicy
(
backOffPolicy
);
return
template
;
}
@Bean
@ConditionalOnSingleCandidate
(
ConnectionFactory
.
class
)
@ConditionalOnProperty
(
prefix
=
"spring.rabbitmq"
,
name
=
"dynamic"
,
matchIfMissing
=
true
)
...
...
@@ -192,7 +194,6 @@ public class RabbitAutoConfiguration {
return
new
RabbitAdmin
(
connectionFactory
);
}
}
@Configuration
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java
View file @
7942d9f7
...
...
@@ -512,8 +512,7 @@ public class RabbitProperties {
private
int
maxAttempts
=
3
;
/**
* Interval between the first and second attempt to publish or deliver
* a message.
* Interval between the first and second attempt to publish or deliver a message.
*/
private
long
initialInterval
=
1000L
;
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/SimpleRabbitListenerContainerFactoryConfigurer.java
View file @
7942d9f7
...
...
@@ -92,14 +92,14 @@ public final class SimpleRabbitListenerContainerFactoryConfigurer {
}
ListenerRetry
retryConfig
=
listenerConfig
.
getRetry
();
if
(
retryConfig
.
isEnabled
())
{
RetryInterceptorBuilder
<?>
builder
=
(
retryConfig
.
isStateless
()
?
RetryInterceptorBuilder
.
stateless
()
:
RetryInterceptorBuilder
.
stateful
());
factory
.
setAdviceChain
(
builder
.
maxAttempts
(
retryConfig
.
getMaxAttempts
())
.
backOffOptions
(
retryConfig
.
getInitialInterval
(),
retryConfig
.
getMultiplier
(),
retryConfig
.
getMaxInterval
())
.
recoverer
(
new
RejectAndDontRequeueRecoverer
())
.
build
());
RetryInterceptorBuilder
<?>
builder
=
(
retryConfig
.
isStateless
()
?
RetryInterceptorBuilder
.
stateless
()
:
RetryInterceptorBuilder
.
stateful
());
builder
.
maxAttempts
(
retryConfig
.
getMaxAttempts
());
builder
.
backOffOptions
(
retryConfig
.
getInitialInterval
(),
retryConfig
.
getMultiplier
(),
retryConfig
.
getMaxInterval
());
builder
.
recoverer
(
new
RejectAndDontRequeueRecoverer
());
factory
.
setAdviceChain
(
builder
.
build
());
}
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfiguration.java
View file @
7942d9f7
...
...
@@ -65,7 +65,7 @@ import org.springframework.util.Assert;
@ConditionalOnMissingBean
(
value
=
CacheManager
.
class
,
name
=
"cacheResolver"
)
@EnableConfigurationProperties
(
CacheProperties
.
class
)
@AutoConfigureBefore
(
HibernateJpaAutoConfiguration
.
class
)
@AutoConfigureAfter
({
CouchbaseAutoConfiguration
.
class
,
HazelcastAutoConfiguration
.
class
,
@AutoConfigureAfter
({
CouchbaseAutoConfiguration
.
class
,
HazelcastAutoConfiguration
.
class
,
RedisAutoConfiguration
.
class
})
@Import
({
CacheManagerCustomizers
.
class
,
CacheConfigurationImportSelector
.
class
})
public
class
CacheAutoConfiguration
{
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheConfigurations.java
View file @
7942d9f7
...
...
@@ -30,9 +30,6 @@ import org.springframework.util.Assert;
*/
final
class
CacheConfigurations
{
private
CacheConfigurations
()
{
}
private
static
final
Map
<
CacheType
,
Class
<?>>
MAPPINGS
;
static
{
...
...
@@ -51,6 +48,9 @@ final class CacheConfigurations {
MAPPINGS
=
Collections
.
unmodifiableMap
(
mappings
);
}
private
CacheConfigurations
()
{
}
public
static
String
getConfigurationClass
(
CacheType
cacheType
)
{
Class
<?>
configurationClass
=
MAPPINGS
.
get
(
cacheType
);
Assert
.
state
(
configurationClass
!=
null
,
"Unknown cache type "
+
cacheType
);
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CouchbaseCacheConfiguration.java
View file @
7942d9f7
...
...
@@ -37,7 +37,7 @@ import org.springframework.context.annotation.Configuration;
* @since 1.4.0
*/
@Configuration
@ConditionalOnClass
({
Bucket
.
class
,
CouchbaseCacheManager
.
class
})
@ConditionalOnClass
({
Bucket
.
class
,
CouchbaseCacheManager
.
class
})
@ConditionalOnMissingBean
(
CacheManager
.
class
)
@ConditionalOnSingleCandidate
(
Bucket
.
class
)
@Conditional
(
CacheCondition
.
class
)
...
...
@@ -60,8 +60,8 @@ public class CouchbaseCacheConfiguration {
public
CouchbaseCacheManager
cacheManager
()
{
List
<
String
>
cacheNames
=
this
.
cacheProperties
.
getCacheNames
();
CouchbaseCacheManager
cacheManager
=
new
CouchbaseCacheManager
(
CacheBuilder
.
newInstance
(
this
.
bucket
)
.
withExpirationInMillis
(
this
.
cacheProperties
.
getCouchbase
().
getExpiration
()),
CacheBuilder
.
newInstance
(
this
.
bucket
)
.
withExpirationInMillis
(
this
.
cacheProperties
.
getCouchbase
().
getExpiration
()),
cacheNames
.
toArray
(
new
String
[
cacheNames
.
size
()]));
return
this
.
customizers
.
customize
(
cacheManager
);
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java
View file @
7942d9f7
...
...
@@ -45,12 +45,11 @@ import org.springframework.data.couchbase.config.CouchbaseConfigurer;
* @since 1.4.0
*/
@Configuration
@ConditionalOnClass
({
CouchbaseBucket
.
class
,
Cluster
.
class
})
@ConditionalOnClass
({
CouchbaseBucket
.
class
,
Cluster
.
class
})
@Conditional
(
CouchbaseAutoConfiguration
.
CouchbaseCondition
.
class
)
@EnableConfigurationProperties
(
CouchbaseProperties
.
class
)
public
class
CouchbaseAutoConfiguration
{
@Configuration
@ConditionalOnMissingBean
(
CouchbaseConfigurer
.
class
)
public
static
class
CouchbaseConfiguration
{
...
...
@@ -77,8 +76,10 @@ public class CouchbaseAutoConfiguration {
@Bean
@Primary
public
ClusterInfo
couchbaseClusterInfo
()
throws
Exception
{
return
couchbaseCluster
().
clusterManager
(
this
.
properties
.
getBucket
().
getName
(),
this
.
properties
.
getBucket
().
getPassword
()).
info
();
return
couchbaseCluster
()
.
clusterManager
(
this
.
properties
.
getBucket
().
getName
(),
this
.
properties
.
getBucket
().
getPassword
())
.
info
();
}
@Bean
...
...
@@ -96,13 +97,12 @@ public class CouchbaseAutoConfiguration {
protected
CouchbaseEnvironment
createEnvironment
(
CouchbaseProperties
properties
)
{
CouchbaseProperties
.
Endpoints
endpoints
=
properties
.
getEnv
().
getEndpoints
();
CouchbaseProperties
.
Timeouts
timeouts
=
properties
.
getEnv
().
getTimeouts
();
DefaultCouchbaseEnvironment
.
Builder
builder
=
DefaultCouchbaseEnvironment
.
builder
()
.
connectTimeout
(
timeouts
.
getConnect
())
DefaultCouchbaseEnvironment
.
Builder
builder
=
DefaultCouchbaseEnvironment
.
builder
().
connectTimeout
(
timeouts
.
getConnect
())
.
kvEndpoints
(
endpoints
.
getKeyValue
())
.
kvTimeout
(
timeouts
.
getKeyValue
())
.
queryEndpoints
(
endpoints
.
getQuery
())
.
queryTimeout
(
timeouts
.
getQuery
())
.
viewEndpoints
(
endpoints
.
getView
())
.
queryTimeout
(
timeouts
.
getQuery
()).
viewEndpoints
(
endpoints
.
getView
())
.
viewTimeout
(
timeouts
.
getView
());
CouchbaseProperties
.
Ssl
ssl
=
properties
.
getEnv
().
getSsl
();
if
(
ssl
.
getEnabled
())
{
...
...
@@ -121,8 +121,8 @@ public class CouchbaseAutoConfiguration {
/**
* Determine if Couchbase should be configured. This happens if either the
* user-configuration defines a {@link CouchbaseConfigurer} or if at least
*
the
"bootstrapHosts" property is specified.
* user-configuration defines a {@link CouchbaseConfigurer} or if at least
the
* "bootstrapHosts" property is specified.
*/
static
class
CouchbaseCondition
extends
AnyNestedCondition
{
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseProperties.java
View file @
7942d9f7
...
...
@@ -57,7 +57,6 @@ public class CouchbaseProperties {
return
this
.
env
;
}
public
static
class
Bucket
{
/**
...
...
@@ -175,7 +174,8 @@ public class CouchbaseProperties {
private
String
keyStorePassword
;
public
Boolean
getEnabled
()
{
return
(
this
.
enabled
!=
null
?
this
.
enabled
:
StringUtils
.
hasText
(
this
.
keyStore
));
return
(
this
.
enabled
!=
null
?
this
.
enabled
:
StringUtils
.
hasText
(
this
.
keyStore
));
}
public
void
setEnabled
(
Boolean
enabled
)
{
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseConfigurerAdapterConfiguration.java
View file @
7942d9f7
...
...
@@ -25,8 +25,8 @@ import org.springframework.context.annotation.Configuration;
import
org.springframework.data.couchbase.config.CouchbaseConfigurer
;
/**
* Adapt the core Couchbase configuration to an expected {@link CouchbaseConfigurer}
*
if
necessary.
* Adapt the core Couchbase configuration to an expected {@link CouchbaseConfigurer}
if
* necessary.
*
* @author Stephane Nicoll
*/
...
...
@@ -44,8 +44,10 @@ class CouchbaseConfigurerAdapterConfiguration {
@Bean
@ConditionalOnMissingBean
public
CouchbaseConfigurer
springBootCouchbaseConfigurer
()
throws
Exception
{
return
new
SpringBootCouchbaseConfigurer
(
this
.
configuration
.
couchbaseEnvironment
(),
this
.
configuration
.
couchbaseCluster
(),
this
.
configuration
.
couchbaseClusterInfo
(),
return
new
SpringBootCouchbaseConfigurer
(
this
.
configuration
.
couchbaseEnvironment
(),
this
.
configuration
.
couchbaseCluster
(),
this
.
configuration
.
couchbaseClusterInfo
(),
this
.
configuration
.
couchbaseClient
());
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataAutoConfiguration.java
View file @
7942d9f7
...
...
@@ -40,7 +40,7 @@ import org.springframework.data.couchbase.repository.CouchbaseRepository;
* @since 1.4.0
*/
@Configuration
@ConditionalOnClass
({
Bucket
.
class
,
CouchbaseRepository
.
class
})
@ConditionalOnClass
({
Bucket
.
class
,
CouchbaseRepository
.
class
})
@AutoConfigureAfter
(
CouchbaseAutoConfiguration
.
class
)
@EnableConfigurationProperties
(
CouchbaseDataProperties
.
class
)
@Import
({
CouchbaseConfigurerAdapterConfiguration
.
class
,
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseRepositoriesRegistrar.java
View file @
7942d9f7
...
...
@@ -29,7 +29,6 @@ import org.springframework.data.repository.config.RepositoryConfigurationExtensi
* Repositories.
*
* @author Eddú Meléndez
* @since 1.4.0
*/
class
CouchbaseRepositoriesRegistrar
extends
AbstractRepositoryConfigurationSourceSupport
{
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/SpringBootCouchbaseDataConfiguration.java
View file @
7942d9f7
...
...
@@ -68,9 +68,7 @@ class SpringBootCouchbaseDataConfiguration extends AbstractCouchbaseDataConfigur
if
(
this
.
properties
.
isAutoIndex
())
{
return
new
IndexManager
(
true
,
true
,
true
);
}
else
{
return
new
IndexManager
(
false
,
false
,
false
);
}
return
new
IndexManager
(
false
,
false
,
false
);
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisRepositoriesAutoConfiguration.java
View file @
7942d9f7
...
...
@@ -43,4 +43,5 @@ import org.springframework.data.redis.repository.support.RedisRepositoryFactoryB
@Import
(
RedisRepositoriesAutoConfigureRegistrar
.
class
)
@AutoConfigureAfter
(
RedisAutoConfiguration
.
class
)
public
class
RedisRepositoriesAutoConfiguration
{
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisRepositoriesAutoConfigureRegistrar.java
View file @
7942d9f7
...
...
@@ -50,6 +50,7 @@ class RedisRepositoriesAutoConfigureRegistrar
@EnableRedisRepositories
private
static
class
EnableRedisRepositoriesConfiguration
{
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.java
View file @
7942d9f7
...
...
@@ -63,7 +63,8 @@ public class H2ConsoleAutoConfiguration {
public
ServletRegistrationBean
h2Console
()
{
String
path
=
this
.
properties
.
getPath
();
String
urlMapping
=
(
path
.
endsWith
(
"/"
)
?
path
+
"*"
:
path
+
"/*"
);
ServletRegistrationBean
registration
=
new
ServletRegistrationBean
(
new
WebServlet
(),
urlMapping
);
ServletRegistrationBean
registration
=
new
ServletRegistrationBean
(
new
WebServlet
(),
urlMapping
);
H2ConsoleProperties
.
Settings
settings
=
this
.
properties
.
getSettings
();
if
(
settings
.
isTrace
())
{
registration
.
addInitParameter
(
"trace"
,
""
);
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfiguration.java
View file @
7942d9f7
...
...
@@ -66,7 +66,8 @@ public class ProjectInfoAutoConfiguration {
@ConditionalOnMissingBean
@Bean
public
BuildProperties
buildProperties
()
throws
Exception
{
return
new
BuildProperties
(
loadFrom
(
this
.
properties
.
getBuild
().
getLocation
(),
"build"
));
return
new
BuildProperties
(
loadFrom
(
this
.
properties
.
getBuild
().
getLocation
(),
"build"
));
}
protected
Properties
loadFrom
(
Resource
location
,
String
prefix
)
throws
IOException
{
...
...
@@ -88,8 +89,10 @@ public class ProjectInfoAutoConfiguration {
@Override
public
ConditionOutcome
getMatchOutcome
(
ConditionContext
context
,
AnnotatedTypeMetadata
metadata
)
{
ResourceLoader
loader
=
context
.
getResourceLoader
()
==
null
?
this
.
defaultResourceLoader
:
context
.
getResourceLoader
();
ResourceLoader
loader
=
context
.
getResourceLoader
();
if
(
loader
==
null
)
{
loader
=
this
.
defaultResourceLoader
;
}
PropertyResolver
propertyResolver
=
context
.
getEnvironment
();
RelaxedPropertyResolver
resolver
=
new
RelaxedPropertyResolver
(
propertyResolver
,
"spring.info.git."
);
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/info/ProjectInfoProperties.java
View file @
7942d9f7
...
...
@@ -53,7 +53,6 @@ public class ProjectInfoProperties {
getGit
().
setLocation
(
defaultGitLocation
);
}
/**
* Build specific info properties.
*/
...
...
@@ -62,7 +61,8 @@ public class ProjectInfoProperties {
/**
* Location of the generated build.properties file.
*/
private
Resource
location
=
new
ClassPathResource
(
"META-INF/boot/build.properties"
);
private
Resource
location
=
new
ClassPathResource
(
"META-INF/boot/build.properties"
);
public
Resource
getLocation
()
{
return
this
.
location
;
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfiguration.java
View file @
7942d9f7
...
...
@@ -65,7 +65,8 @@ public class JmsAutoConfiguration {
public
JmsTemplate
jmsTemplate
(
ConnectionFactory
connectionFactory
)
{
JmsTemplate
jmsTemplate
=
new
JmsTemplate
(
connectionFactory
);
jmsTemplate
.
setPubSubDomain
(
this
.
properties
.
isPubSubDomain
());
DestinationResolver
destinationResolver
=
this
.
destinationResolver
.
getIfUnique
();
DestinationResolver
destinationResolver
=
this
.
destinationResolver
.
getIfUnique
();
if
(
destinationResolver
!=
null
)
{
jmsTemplate
.
setDestinationResolver
(
destinationResolver
);
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java
View file @
7942d9f7
...
...
@@ -55,7 +55,8 @@ class ActiveMQConnectionFactoryConfiguration {
@Bean
(
destroyMethod
=
"stop"
)
@ConditionalOnProperty
(
prefix
=
"spring.activemq.pool"
,
name
=
"enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
false
)
@ConfigurationProperties
(
"spring.activemq.pool.configuration"
)
public
PooledConnectionFactory
pooledJmsConnectionFactory
(
ActiveMQProperties
properties
)
{
public
PooledConnectionFactory
pooledJmsConnectionFactory
(
ActiveMQProperties
properties
)
{
PooledConnectionFactory
pooledConnectionFactory
=
new
PooledConnectionFactory
(
new
ActiveMQConnectionFactoryFactory
(
properties
)
.
createConnectionFactory
(
ActiveMQConnectionFactory
.
class
));
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQProperties.java
View file @
7942d9f7
...
...
@@ -67,6 +67,26 @@ public class ActiveMQProperties {
this
.
inMemory
=
inMemory
;
}
/**
* Get if pooling is enabled.
* @return if pooling is enabled
* @deprecated since 1.4 in favor of "spring.activemq.pool.enabled"
*/
@Deprecated
public
boolean
isPooled
()
{
return
getPool
().
isEnabled
();
}
/**
* Set if pooling is enabled.
* @param pooled the pooling enabled value
* @deprecated since 1.4 in favor of "spring.activemq.pool.enabled"
*/
@Deprecated
public
void
setPooled
(
boolean
pooled
)
{
getPool
().
setEnabled
(
pooled
);
}
public
String
getUser
()
{
return
this
.
user
;
}
...
...
@@ -91,7 +111,7 @@ public class ActiveMQProperties {
this
.
pool
=
pool
;
}
p
rotected
static
class
Pool
{
p
ublic
static
class
Pool
{
/**
* Whether a PooledConnectionFactory should be created instead of a regular
...
...
@@ -147,4 +167,5 @@ public class ActiveMQProperties {
}
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQXAConnectionFactoryConfiguration.java
View file @
7942d9f7
...
...
@@ -45,7 +45,7 @@ import org.springframework.context.annotation.Primary;
class
ActiveMQXAConnectionFactoryConfiguration
{
@Primary
@Bean
(
name
=
{
"jmsConnectionFactory"
,
"xaJmsConnectionFactory"
})
@Bean
(
name
=
{
"jmsConnectionFactory"
,
"xaJmsConnectionFactory"
})
public
ConnectionFactory
jmsConnectionFactory
(
ActiveMQProperties
properties
,
XAConnectionFactoryWrapper
wrapper
)
throws
Exception
{
ActiveMQXAConnectionFactory
connectionFactory
=
new
ActiveMQConnectionFactoryFactory
(
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java
View file @
7942d9f7
...
...
@@ -158,11 +158,14 @@ public class RabbitAutoConfigurationTests {
DirectFieldAccessor
dfa
=
new
DirectFieldAccessor
(
rabbitTemplate
);
assertThat
(
dfa
.
getPropertyValue
(
"receiveTimeout"
)).
isEqualTo
(
123L
);
assertThat
(
dfa
.
getPropertyValue
(
"replyTimeout"
)).
isEqualTo
(
456L
);
RetryTemplate
retryTemplate
=
(
RetryTemplate
)
dfa
.
getPropertyValue
(
"retryTemplate"
);
RetryTemplate
retryTemplate
=
(
RetryTemplate
)
dfa
.
getPropertyValue
(
"retryTemplate"
);
assertThat
(
retryTemplate
).
isNotNull
();
dfa
=
new
DirectFieldAccessor
(
retryTemplate
);
SimpleRetryPolicy
retryPolicy
=
(
SimpleRetryPolicy
)
dfa
.
getPropertyValue
(
"retryPolicy"
);
ExponentialBackOffPolicy
backOffPolicy
=
(
ExponentialBackOffPolicy
)
dfa
.
getPropertyValue
(
"backOffPolicy"
);
SimpleRetryPolicy
retryPolicy
=
(
SimpleRetryPolicy
)
dfa
.
getPropertyValue
(
"retryPolicy"
);
ExponentialBackOffPolicy
backOffPolicy
=
(
ExponentialBackOffPolicy
)
dfa
.
getPropertyValue
(
"backOffPolicy"
);
assertThat
(
retryPolicy
.
getMaxAttempts
()).
isEqualTo
(
4
);
assertThat
(
backOffPolicy
.
getInitialInterval
()).
isEqualTo
(
2000
);
assertThat
(
backOffPolicy
.
getMultiplier
()).
isEqualTo
(
1.5
);
...
...
@@ -182,8 +185,7 @@ public class RabbitAutoConfigurationTests {
@Test
public
void
testConnectionFactoryCacheSettings
()
{
load
(
TestConfiguration
.
class
,
"spring.rabbitmq.cache.channel.size=23"
,
load
(
TestConfiguration
.
class
,
"spring.rabbitmq.cache.channel.size=23"
,
"spring.rabbitmq.cache.channel.checkoutTimeout=1000"
,
"spring.rabbitmq.cache.connection.mode=CONNECTION"
,
"spring.rabbitmq.cache.connection.size=2"
);
...
...
@@ -273,16 +275,20 @@ public class RabbitAutoConfigurationTests {
assertThat
(
dfa
.
getPropertyValue
(
"txSize"
)).
isEqualTo
(
20
);
assertThat
(
dfa
.
getPropertyValue
(
"messageConverter"
))
.
isSameAs
(
this
.
context
.
getBean
(
"myMessageConverter"
));
assertThat
(
dfa
.
getPropertyValue
(
"defaultRequeueRejected"
)).
isEqualTo
(
Boolean
.
FALSE
);
assertThat
(
dfa
.
getPropertyValue
(
"defaultRequeueRejected"
))
.
isEqualTo
(
Boolean
.
FALSE
);
Advice
[]
adviceChain
=
(
Advice
[])
dfa
.
getPropertyValue
(
"adviceChain"
);
assertThat
(
adviceChain
).
isNotNull
();
assertThat
(
adviceChain
.
length
).
isEqualTo
(
1
);
dfa
=
new
DirectFieldAccessor
(
adviceChain
[
0
]);
RetryTemplate
retryTemplate
=
(
RetryTemplate
)
dfa
.
getPropertyValue
(
"retryOperations"
);
RetryTemplate
retryTemplate
=
(
RetryTemplate
)
dfa
.
getPropertyValue
(
"retryOperations"
);
assertThat
(
retryTemplate
).
isNotNull
();
dfa
=
new
DirectFieldAccessor
(
retryTemplate
);
SimpleRetryPolicy
retryPolicy
=
(
SimpleRetryPolicy
)
dfa
.
getPropertyValue
(
"retryPolicy"
);
ExponentialBackOffPolicy
backOffPolicy
=
(
ExponentialBackOffPolicy
)
dfa
.
getPropertyValue
(
"backOffPolicy"
);
SimpleRetryPolicy
retryPolicy
=
(
SimpleRetryPolicy
)
dfa
.
getPropertyValue
(
"retryPolicy"
);
ExponentialBackOffPolicy
backOffPolicy
=
(
ExponentialBackOffPolicy
)
dfa
.
getPropertyValue
(
"backOffPolicy"
);
assertThat
(
retryPolicy
.
getMaxAttempts
()).
isEqualTo
(
4
);
assertThat
(
backOffPolicy
.
getInitialInterval
()).
isEqualTo
(
2000
);
assertThat
(
backOffPolicy
.
getMultiplier
()).
isEqualTo
(
1.5
);
...
...
@@ -427,10 +433,12 @@ public class RabbitAutoConfigurationTests {
@Configuration
@EnableRabbit
protected
static
class
EnableRabbitConfiguration
{
}
@Configuration
protected
static
class
NoEnableRabbitConfiguration
{
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java
View file @
7942d9f7
...
...
@@ -214,7 +214,8 @@ public class CacheAutoConfigurationTests {
@Test
public
void
couchbaseCacheExplicit
()
{
load
(
CouchbaseCacheConfiguration
.
class
,
"spring.cache.type=couchbase"
);
CouchbaseCacheManager
cacheManager
=
validateCacheManager
(
CouchbaseCacheManager
.
class
);
CouchbaseCacheManager
cacheManager
=
validateCacheManager
(
CouchbaseCacheManager
.
class
);
assertThat
(
cacheManager
.
getCacheNames
()).
isEmpty
();
}
...
...
@@ -228,24 +229,29 @@ public class CacheAutoConfigurationTests {
public
void
couchbaseCacheExplicitWithCaches
()
{
load
(
CouchbaseCacheConfiguration
.
class
,
"spring.cache.type=couchbase"
,
"spring.cache.cacheNames[0]=foo"
,
"spring.cache.cacheNames[1]=bar"
);
CouchbaseCacheManager
cacheManager
=
validateCacheManager
(
CouchbaseCacheManager
.
class
);
CouchbaseCacheManager
cacheManager
=
validateCacheManager
(
CouchbaseCacheManager
.
class
);
assertThat
(
cacheManager
.
getCacheNames
()).
containsOnly
(
"foo"
,
"bar"
);
Cache
cache
=
cacheManager
.
getCache
(
"foo"
);
assertThat
(
cache
).
isInstanceOf
(
CouchbaseCache
.
class
);
assertThat
(((
CouchbaseCache
)
cache
).
getTtl
()).
isEqualTo
(
0
);
assertThat
(((
CouchbaseCache
)
cache
).
getNativeCache
()).
isEqualTo
(
this
.
context
.
getBean
(
"bucket"
));
assertThat
(((
CouchbaseCache
)
cache
).
getNativeCache
())
.
isEqualTo
(
this
.
context
.
getBean
(
"bucket"
));
}
@Test
public
void
couchbaseCacheExplicitWithTtl
()
{
load
(
CouchbaseCacheConfiguration
.
class
,
"spring.cache.type=couchbase"
,
"spring.cache.cacheNames=foo,bar"
,
"spring.cache.couchbase.expiration=2000"
);
CouchbaseCacheManager
cacheManager
=
validateCacheManager
(
CouchbaseCacheManager
.
class
);
"spring.cache.cacheNames=foo,bar"
,
"spring.cache.couchbase.expiration=2000"
);
CouchbaseCacheManager
cacheManager
=
validateCacheManager
(
CouchbaseCacheManager
.
class
);
assertThat
(
cacheManager
.
getCacheNames
()).
containsOnly
(
"foo"
,
"bar"
);
Cache
cache
=
cacheManager
.
getCache
(
"foo"
);
assertThat
(
cache
).
isInstanceOf
(
CouchbaseCache
.
class
);
assertThat
(((
CouchbaseCache
)
cache
).
getTtl
()).
isEqualTo
(
2000
);
assertThat
(((
CouchbaseCache
)
cache
).
getNativeCache
()).
isEqualTo
(
this
.
context
.
getBean
(
"bucket"
));
assertThat
(((
CouchbaseCache
)
cache
).
getNativeCache
())
.
isEqualTo
(
this
.
context
.
getBean
(
"bucket"
));
}
@Test
...
...
@@ -789,7 +795,8 @@ public class CacheAutoConfigurationTests {
}
@Configuration
@Import
({
CouchbaseCacheConfiguration
.
class
,
CacheManagerCustomizersConfiguration
.
class
})
@Import
({
CouchbaseCacheConfiguration
.
class
,
CacheManagerCustomizersConfiguration
.
class
})
static
class
CouchbaseCacheAndCustomizersConfiguration
{
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/AbstractCouchbaseAutoConfigurationTests.java
View file @
7942d9f7
...
...
@@ -23,6 +23,8 @@ import org.springframework.boot.test.EnvironmentTestUtils;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
/**
* Base class for {@link CouchbaseAutoConfiguration} tests.
*
* @author Stephane Nicoll
*/
public
abstract
class
AbstractCouchbaseAutoConfigurationTests
{
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationIntegrationTests.java
View file @
7942d9f7
...
...
@@ -59,7 +59,6 @@ public class CouchbaseAutoConfigurationIntegrationTests
assertThat
(
this
.
context
.
getBeansOfType
(
Bucket
.
class
)).
hasSize
(
2
);
}
@Configuration
static
class
CustomConfiguration
{
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationTests.java
View file @
7942d9f7
...
...
@@ -33,7 +33,8 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Eddú Meléndez
* @author Stephane Nicoll
*/
public
class
CouchbaseAutoConfigurationTests
extends
AbstractCouchbaseAutoConfigurationTests
{
public
class
CouchbaseAutoConfigurationTests
extends
AbstractCouchbaseAutoConfigurationTests
{
@Rule
public
ExpectedException
thrown
=
ExpectedException
.
none
();
...
...
@@ -47,8 +48,7 @@ public class CouchbaseAutoConfigurationTests extends AbstractCouchbaseAutoConfig
@Test
public
void
bootstrapHostsNotRequiredIfCouchbaseConfigurerIsSet
()
{
load
(
CouchbaseTestConfigurer
.
class
);
assertThat
(
this
.
context
.
getBeansOfType
(
CouchbaseTestConfigurer
.
class
))
.
hasSize
(
1
);
assertThat
(
this
.
context
.
getBeansOfType
(
CouchbaseTestConfigurer
.
class
)).
hasSize
(
1
);
// No beans are going to be created
assertNoCouchbaseBeans
();
}
...
...
@@ -56,8 +56,7 @@ public class CouchbaseAutoConfigurationTests extends AbstractCouchbaseAutoConfig
@Test
public
void
bootstrapHostsIgnoredIfCouchbaseConfigurerIsSet
()
{
load
(
CouchbaseTestConfigurer
.
class
,
"spring.couchbase.bootstrapHosts=localhost"
);
assertThat
(
this
.
context
.
getBeansOfType
(
CouchbaseTestConfigurer
.
class
))
.
hasSize
(
1
);
assertThat
(
this
.
context
.
getBeansOfType
(
CouchbaseTestConfigurer
.
class
)).
hasSize
(
1
);
assertNoCouchbaseBeans
();
}
...
...
@@ -114,11 +113,12 @@ public class CouchbaseAutoConfigurationTests extends AbstractCouchbaseAutoConfig
assertThat
(
env
.
sslKeystorePassword
()).
isNull
();
}
private
DefaultCouchbaseEnvironment
customizeEnv
(
String
...
environment
)
throws
Exception
{
private
DefaultCouchbaseEnvironment
customizeEnv
(
String
...
environment
)
throws
Exception
{
load
(
CouchbaseTestConfigurer
.
class
,
environment
);
CouchbaseProperties
properties
=
this
.
context
.
getBean
(
CouchbaseProperties
.
class
);
return
(
DefaultCouchbaseEnvironment
)
new
CouchbaseAutoConfiguration
.
CouchbaseConfiguration
(
properties
)
.
couchbaseEnvironment
();
return
(
DefaultCouchbaseEnvironment
)
new
CouchbaseAutoConfiguration
.
CouchbaseConfiguration
(
properties
)
.
couchbaseEnvironment
();
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseTestServer.java
View file @
7942d9f7
...
...
@@ -25,14 +25,14 @@ import com.couchbase.client.java.env.CouchbaseEnvironment;
import
com.couchbase.client.java.env.DefaultCouchbaseEnvironment
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.junit.Assum
e
;
import
org.junit.Assum
ptionViolatedException
;
import
org.junit.rules.TestRule
;
import
org.junit.runner.Description
;
import
org.junit.runners.model.Statement
;
/**
* {@link TestRule} for working with an optional Couchbase server. Expects
*
a default
{@link Bucket} with no password to be available on localhost.
* {@link TestRule} for working with an optional Couchbase server. Expects
a default
* {@link Bucket} with no password to be available on localhost.
*
* @author Stephane Nicoll
*/
...
...
@@ -40,19 +40,20 @@ public class CouchbaseTestServer implements TestRule {
private
static
final
Log
logger
=
LogFactory
.
getLog
(
CouchbaseTestServer
.
class
);
private
CouchbaseEnvironment
env
;
private
CouchbaseEnvironment
env
ironment
;
private
Cluster
cluster
;
@Override
public
Statement
apply
(
Statement
base
,
Description
description
)
{
try
{
this
.
env
=
DefaultCouchbaseEnvironment
.
create
();
this
.
cluster
=
CouchbaseCluster
.
create
(
this
.
env
,
"localhost"
);
this
.
environment
=
DefaultCouchbaseEnvironment
.
create
();
this
.
cluster
=
CouchbaseCluster
.
create
(
this
.
environment
,
"localhost"
);
testConnection
(
this
.
cluster
);
return
new
CouchbaseStatement
(
base
,
this
.
env
,
this
.
cluster
);
return
new
CouchbaseStatement
(
base
,
this
.
env
ironment
,
this
.
cluster
);
}
catch
(
Exception
e
)
{
catch
(
Exception
e
x
)
{
logger
.
info
(
"No couchbase server available"
);
return
new
SkipStatement
();
}
...
...
@@ -64,10 +65,10 @@ public class CouchbaseTestServer implements TestRule {
}
/**
* @return the
couchbase env
if any
* @return the
Couchbase environment
if any
*/
public
CouchbaseEnvironment
get
Env
()
{
return
this
.
env
;
public
CouchbaseEnvironment
get
CouchbaseEnvironment
()
{
return
this
.
env
ironment
;
}
/**
...
...
@@ -77,16 +78,18 @@ public class CouchbaseTestServer implements TestRule {
return
this
.
cluster
;
}
private
static
class
CouchbaseStatement
extends
Statement
{
private
final
Statement
base
;
private
final
CouchbaseEnvironment
env
;
private
final
CouchbaseEnvironment
environment
;
private
final
Cluster
cluster
;
CouchbaseStatement
(
Statement
base
,
CouchbaseEnvironment
env
,
Cluster
cluster
)
{
CouchbaseStatement
(
Statement
base
,
CouchbaseEnvironment
environment
,
Cluster
cluster
)
{
this
.
base
=
base
;
this
.
env
=
env
;
this
.
env
ironment
=
environment
;
this
.
cluster
=
cluster
;
}
...
...
@@ -98,10 +101,11 @@ public class CouchbaseTestServer implements TestRule {
finally
{
try
{
this
.
cluster
.
disconnect
();
this
.
env
.
shutdownAsync
();
this
.
env
ironment
.
shutdownAsync
();
}
catch
(
Exception
ex
)
{
logger
.
warn
(
"Exception while trying to cleanup couchbase resource"
,
ex
);
logger
.
warn
(
"Exception while trying to cleanup couchbase resource"
,
ex
);
}
}
}
...
...
@@ -111,8 +115,8 @@ public class CouchbaseTestServer implements TestRule {
@Override
public
void
evaluate
()
throws
Throwable
{
Assume
.
assumeTrue
(
"Skipping test due to Couchbase "
+
"not being available"
,
false
);
throw
new
AssumptionViolatedException
(
"Skipping test due to Couchbase not being available"
);
}
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataAutoConfigurationTests.java
View file @
7942d9f7
...
...
@@ -65,14 +65,15 @@ public class CouchbaseDataAutoConfigurationTests {
@Test
public
void
customConfiguration
()
{
load
(
CustomCouchbaseConfiguration
.
class
);
CouchbaseTemplate
couchbaseTemplate
=
this
.
context
.
getBean
(
CouchbaseTemplate
.
class
);
assertThat
(
couchbaseTemplate
.
getDefaultConsistency
()).
isEqualTo
(
Consistency
.
STRONGLY_CONSISTENT
);
CouchbaseTemplate
couchbaseTemplate
=
this
.
context
.
getBean
(
CouchbaseTemplate
.
class
);
assertThat
(
couchbaseTemplate
.
getDefaultConsistency
())
.
isEqualTo
(
Consistency
.
STRONGLY_CONSISTENT
);
}
@Test
public
void
validatorIsPresent
()
{
load
(
ValidatorConfiguration
.
class
);
ValidatingCouchbaseEventListener
listener
=
this
.
context
.
getBean
(
ValidatingCouchbaseEventListener
.
class
);
assertThat
(
new
DirectFieldAccessor
(
listener
).
getPropertyValue
(
"validator"
))
...
...
@@ -90,8 +91,7 @@ public class CouchbaseDataAutoConfigurationTests {
@Test
public
void
enableAutoIndex
()
{
load
(
CouchbaseTestConfigurer
.
class
,
"spring.data.couchbase.auto-index=true"
);
load
(
CouchbaseTestConfigurer
.
class
,
"spring.data.couchbase.auto-index=true"
);
IndexManager
indexManager
=
this
.
context
.
getBean
(
IndexManager
.
class
);
assertThat
(
indexManager
.
isIgnoreViews
()).
isFalse
();
assertThat
(
indexManager
.
isIgnoreN1qlPrimary
()).
isFalse
();
...
...
@@ -115,13 +115,11 @@ public class CouchbaseDataAutoConfigurationTests {
context
.
register
(
config
);
}
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
CouchbaseAutoConfiguration
.
class
,
CouchbaseDataAutoConfiguration
.
class
);
CouchbaseAutoConfiguration
.
class
,
CouchbaseDataAutoConfiguration
.
class
);
context
.
refresh
();
this
.
context
=
context
;
}
@Configuration
@Import
(
CouchbaseTestConfigurer
.
class
)
static
class
ValidatorConfiguration
{
...
...
@@ -145,6 +143,7 @@ public class CouchbaseDataAutoConfigurationTests {
protected
Consistency
getDefaultConsistency
()
{
return
Consistency
.
STRONGLY_CONSISTENT
;
}
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseRepositoriesAutoConfigurationTests.java
View file @
7942d9f7
...
...
@@ -82,8 +82,7 @@ public class CouchbaseRepositoriesAutoConfigurationTests {
context
.
register
(
config
);
}
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
CouchbaseAutoConfiguration
.
class
,
CouchbaseDataAutoConfiguration
.
class
,
CouchbaseAutoConfiguration
.
class
,
CouchbaseDataAutoConfiguration
.
class
,
CouchbaseRepositoriesAutoConfiguration
.
class
);
context
.
refresh
();
this
.
context
=
context
;
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisRepositoriesAutoConfigurationTests.java
View file @
7942d9f7
...
...
@@ -43,8 +43,7 @@ public class RedisRepositoriesAutoConfigurationTests {
@Rule
public
RedisTestServer
redis
=
new
RedisTestServer
();
private
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
private
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
@After
public
void
close
()
{
...
...
@@ -53,8 +52,8 @@ public class RedisRepositoriesAutoConfigurationTests {
@Test
public
void
testDefaultRepositoryConfiguration
()
{
this
.
context
.
register
(
TestConfiguration
.
class
,
Redis
AutoConfiguration
.
class
,
Redis
RepositoriesAutoConfiguration
.
class
,
this
.
context
.
register
(
TestConfiguration
.
class
,
RedisAutoConfiguration
.
class
,
RedisRepositoriesAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBean
(
CityRepository
.
class
)).
isNotNull
();
...
...
@@ -62,8 +61,7 @@ public class RedisRepositoriesAutoConfigurationTests {
@Test
public
void
testNoRepositoryConfiguration
()
{
this
.
context
.
register
(
EmptyConfiguration
.
class
,
RedisAutoConfiguration
.
class
,
this
.
context
.
register
(
EmptyConfiguration
.
class
,
RedisAutoConfiguration
.
class
,
RedisRepositoriesAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
...
...
@@ -72,8 +70,7 @@ public class RedisRepositoriesAutoConfigurationTests {
@Test
public
void
doesNotTriggerDefaultRepositoryDetectionIfCustomized
()
{
this
.
context
.
register
(
CustomizedConfiguration
.
class
,
RedisAutoConfiguration
.
class
,
this
.
context
.
register
(
CustomizedConfiguration
.
class
,
RedisAutoConfiguration
.
class
,
RedisRepositoriesAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfigurationTests.java
View file @
7942d9f7
...
...
@@ -70,12 +70,12 @@ public class H2ConsoleAutoConfigurationTests {
"spring.h2.console.enabled:true"
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBeansOfType
(
ServletRegistrationBean
.
class
)).
hasSize
(
1
);
assertThat
(
this
.
context
.
getBean
(
ServletRegistrationBean
.
class
).
getUrlMappings
())
.
contains
(
"/h2-console/*"
);
assertThat
(
this
.
context
.
getBean
(
ServletRegistrationBean
.
class
).
getInitParameters
()).
doesNotContainKey
(
"trace"
);
assertThat
(
this
.
context
.
getBean
(
ServletRegistrationBean
.
class
).
getInitParameters
()).
doesNotContainKey
(
"webAllowOthers"
);
ServletRegistrationBean
registrationBean
=
this
.
context
.
getBean
(
ServletRegistrationBean
.
class
);
assertThat
(
registrationBean
.
getUrlMappings
()).
contains
(
"/h2-console/*"
);
assertThat
(
registrationBean
.
getInitParameters
()).
doesNotContainKey
(
"trace"
);
assertThat
(
registrationBean
.
getInitParameters
())
.
doesNotContainKey
(
"webAllowOthers"
);
}
@Test
...
...
@@ -114,17 +114,16 @@ public class H2ConsoleAutoConfigurationTests {
public
void
customInitParameters
()
{
this
.
context
.
register
(
H2ConsoleAutoConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.h2.console.enabled:true"
,
"spring.h2.console.settings.trace=true"
,
"spring.h2.console.enabled:true"
,
"spring.h2.console.settings.trace=true"
,
"spring.h2.console.settings.webAllowOthers=true"
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBeansOfType
(
ServletRegistrationBean
.
class
)).
hasSize
(
1
);
assertThat
(
this
.
context
.
getBean
(
ServletRegistrationBean
.
class
).
getUrlMappings
())
.
contains
(
"/h2-console/*"
);
assertThat
(
this
.
context
.
getBean
(
ServletRegistrationBean
.
class
).
getInitParameters
()).
containsEntry
(
"trace"
,
""
);
assertThat
(
this
.
context
.
getBean
(
ServletRegistrationBean
.
class
).
getInitParameters
()).
containsEntry
(
"webAllowOthers"
,
""
);
ServletRegistrationBean
registrationBean
=
this
.
context
.
getBean
(
ServletRegistrationBean
.
class
);
assertThat
(
registrationBean
.
getUrlMappings
()).
contains
(
"/h2-console/*"
);
assertThat
(
registrationBean
.
getInitParameters
()).
containsEntry
(
"trace"
,
""
);
assertThat
(
registrationBean
.
getInitParameters
()).
containsEntry
(
"webAllowOthers"
,
""
);
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfigurationTests.java
View file @
7942d9f7
...
...
@@ -51,7 +51,8 @@ public class ProjectInfoAutoConfigurationTests {
@Test
public
void
gitPropertiesUnavailableIfResourceNotAvailable
()
{
load
();
Map
<
String
,
GitProperties
>
beans
=
this
.
context
.
getBeansOfType
(
GitProperties
.
class
);
Map
<
String
,
GitProperties
>
beans
=
this
.
context
.
getBeansOfType
(
GitProperties
.
class
);
assertThat
(
beans
).
hasSize
(
0
);
}
...
...
@@ -61,7 +62,8 @@ public class ProjectInfoAutoConfigurationTests {
"spring.git.properties=classpath:/org/springframework/boot/autoconfigure/info/git-no-data.properties"
);
GitProperties
gitProperties
=
this
.
context
.
getBean
(
GitProperties
.
class
);
assertThat
(
gitProperties
.
getBranch
()).
isNull
();
assertThat
(
gitProperties
.
getCommitId
()).
isEqualTo
(
"f95038ec09e29d8f91982fd1cbcc0f3b131b1d0a"
);
assertThat
(
gitProperties
.
getCommitId
())
.
isEqualTo
(
"f95038ec09e29d8f91982fd1cbcc0f3b131b1d0a"
);
assertThat
(
gitProperties
.
getCommitTime
().
getTime
()).
isEqualTo
(
1456995720000L
);
}
...
...
@@ -70,7 +72,8 @@ public class ProjectInfoAutoConfigurationTests {
load
(
"spring.git.properties=classpath:/org/springframework/boot/autoconfigure/info/git-epoch.properties"
);
GitProperties
gitProperties
=
this
.
context
.
getBean
(
GitProperties
.
class
);
assertThat
(
gitProperties
.
getBranch
()).
isEqualTo
(
"master"
);
assertThat
(
gitProperties
.
getCommitId
()).
isEqualTo
(
"5009933788f5f8c687719de6a697074ff80b1b69"
);
assertThat
(
gitProperties
.
getCommitId
())
.
isEqualTo
(
"5009933788f5f8c687719de6a697074ff80b1b69"
);
assertThat
(
gitProperties
.
getCommitTime
().
getTime
()).
isEqualTo
(
1457103850000L
);
}
...
...
@@ -114,7 +117,8 @@ public class ProjectInfoAutoConfigurationTests {
@Test
public
void
buildPropertiesCustomInvalidLocation
()
{
load
(
"spring.info.build.location=classpath:/org/acme/no-build.properties"
);
Map
<
String
,
BuildProperties
>
beans
=
this
.
context
.
getBeansOfType
(
BuildProperties
.
class
);
Map
<
String
,
BuildProperties
>
beans
=
this
.
context
.
getBeansOfType
(
BuildProperties
.
class
);
assertThat
(
beans
).
hasSize
(
0
);
}
...
...
@@ -122,7 +126,8 @@ public class ProjectInfoAutoConfigurationTests {
public
void
buildPropertiesFallbackWithBuildInfoBean
()
{
load
(
CustomInfoPropertiesConfiguration
.
class
);
BuildProperties
buildProperties
=
this
.
context
.
getBean
(
BuildProperties
.
class
);
assertThat
(
buildProperties
).
isSameAs
(
this
.
context
.
getBean
(
"customBuildProperties"
));
assertThat
(
buildProperties
)
.
isSameAs
(
this
.
context
.
getBean
(
"customBuildProperties"
));
}
private
void
load
(
String
...
environment
)
{
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQAutoConfigurationTests.java
View file @
7942d9f7
...
...
@@ -21,7 +21,6 @@ import javax.jms.JMSException;
import
org.apache.activemq.ActiveMQConnectionFactory
;
import
org.apache.activemq.pool.PooledConnectionFactory
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration
;
...
...
@@ -64,21 +63,22 @@ public class ActiveMQAutoConfigurationTests {
@Test
public
void
customPooledConnectionFactoryConfiguration
()
{
load
(
EmptyConfiguration
.
class
,
"spring.activemq.pool.enabled:true
"
,
"spring.activemq.pool.maxConnections:256
"
,
"spring.activemq.pool.idleTimeout:512
"
,
"spring.activemq.pool.expiryTimeout:4096
"
,
"spring.activemq.pool.configuration.maximumActiveSessionPerConnection:1024"
,
"spring.activemq.pool.configuration.timeBetweenExpirationCheckMillis:2048"
);
ConnectionFactory
connectionFactory
=
this
.
context
.
getBean
(
ConnectionFactory
.
class
);
load
(
EmptyConfiguration
.
class
,
"spring.activemq.pool.enabled:true"
,
"spring.activemq.pool.maxConnections:256
"
,
"spring.activemq.pool.idleTimeout:512
"
,
"spring.activemq.pool.expiryTimeout:4096
"
,
"spring.activemq.pool.configuration.maximumActiveSessionPerConnection:1024
"
,
"spring.activemq.pool.configuration.timeBetweenExpirationCheckMillis:2048"
);
ConnectionFactory
connectionFactory
=
this
.
context
.
getBean
(
ConnectionFactory
.
class
);
assertThat
(
connectionFactory
).
isInstanceOf
(
PooledConnectionFactory
.
class
);
PooledConnectionFactory
pooledConnectionFactory
=
(
PooledConnectionFactory
)
connectionFactory
;
assertThat
(
pooledConnectionFactory
.
getMaxConnections
()).
isEqualTo
(
256
);
assertThat
(
pooledConnectionFactory
.
getIdleTimeout
()).
isEqualTo
(
512
);
assertThat
(
pooledConnectionFactory
.
getMaximumActiveSessionPerConnection
()).
isEqualTo
(
1024
);
assertThat
(
pooledConnectionFactory
.
getTimeBetweenExpirationCheckMillis
()).
isEqualTo
(
2048
);
assertThat
(
pooledConnectionFactory
.
getMaximumActiveSessionPerConnection
())
.
isEqualTo
(
1024
);
assertThat
(
pooledConnectionFactory
.
getTimeBetweenExpirationCheckMillis
())
.
isEqualTo
(
2048
);
assertThat
(
pooledConnectionFactory
.
getExpiryTimeout
()).
isEqualTo
(
4096
);
}
...
...
@@ -119,6 +119,7 @@ public class ActiveMQAutoConfigurationTests {
public
ConnectionFactory
connectionFactory
()
{
return
mock
(
ConnectionFactory
.
class
);
}
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQPropertiesTests.java
View file @
7942d9f7
...
...
@@ -21,7 +21,7 @@ import org.junit.Test;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ActiveMQProperties} and
ActiveMQConnectionFactoryFactory
.
* Tests for {@link ActiveMQProperties} and
{@link ActiveMQConnectionFactoryFactory}
.
*
* @author Stephane Nicoll
* @author Aurélien Leboulanger
...
...
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
7942d9f7
...
...
@@ -3231,6 +3231,7 @@ SSL support:
Check the `spring.couchbase.env.*` properties for more details.
[[boot-features-spring-data-couchbase-repositories]]
==== Spring Data Couchbase repositories
Spring Data includes repository support for Couchbase. For complete details of Spring
...
...
@@ -3266,6 +3267,7 @@ If you add a `@Bean` of your own of type `CouchbaseTemplate` named `couchbaseTem
will replace the default.
[[boot-features-caching]]
== Caching
The Spring Framework provides support for transparently adding caching to an application.
...
...
@@ -3947,6 +3949,8 @@ You can modify this behavior in two ways; set the `defaultRequeueRejected` prope
will be attempted; or, throw an `AmqpRejectAndDontRequeueException` to signal the message should be rejected.
This is the mechanism used when retries are enabled and the maximum delivery attempts is reached.
[[boot-features-email]]
== Sending email
The Spring Framework provides an easy abstraction for sending email using the
...
...
spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildInfoMojo.java
View file @
7942d9f7
...
...
@@ -20,6 +20,7 @@ import java.io.File;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Map
;
...
...
@@ -34,7 +35,8 @@ import org.apache.maven.plugins.annotations.Parameter;
import
org.apache.maven.project.MavenProject
;
/**
* Generate a {@code build.properties} file based the content of the current {@link MavenProject}.
* Generate a {@code build.properties} file based the content of the current
* {@link MavenProject}.
*
* @author Stephane Nicoll
* @since 1.4.0
...
...
@@ -64,27 +66,30 @@ public class BuildInfoMojo extends AbstractMojo {
@Override
public
void
execute
()
throws
MojoExecutionException
,
MojoFailureException
{
Properties
properties
=
createBuildInfo
();
FileOutputStream
fos
=
null
;
try
{
createFileIfNecessary
(
this
.
outputFile
);
fos
=
new
FileOutputStream
(
this
.
outputFile
);
properties
.
store
(
fos
,
"Properties"
);
FileOutputStream
outputStream
=
new
FileOutputStream
(
this
.
outputFile
);
try
{
properties
.
store
(
outputStream
,
"Properties"
);
}
finally
{
closeQuietly
(
outputStream
);
}
}
catch
(
FileNotFoundException
e
)
{
throw
new
MojoExecutionException
(
e
.
getMessage
(),
e
);
catch
(
FileNotFoundException
e
x
)
{
throw
new
MojoExecutionException
(
e
x
.
getMessage
(),
ex
);
}
catch
(
IOException
e
)
{
throw
new
MojoExecutionException
(
e
.
getMessage
(),
e
);
}
finally
{
try
{
if
(
fos
!=
null
)
{
fos
.
close
();
}
}
catch
(
IOException
e
)
{
getLog
().
error
(
"Error closing FileOutputStream: "
+
fos
);
}
}
private
void
closeQuietly
(
OutputStream
outputStream
)
{
try
{
outputStream
.
close
();
}
catch
(
IOException
ex
)
{
getLog
().
error
(
"Error closing FileOutputStream: "
+
outputStream
);
}
}
...
...
@@ -108,7 +113,8 @@ public class BuildInfoMojo extends AbstractMojo {
return
sdf
.
format
(
date
);
}
private
void
createFileIfNecessary
(
File
file
)
throws
MojoExecutionException
,
IOException
{
private
void
createFileIfNecessary
(
File
file
)
throws
MojoExecutionException
,
IOException
{
if
(
file
.
exists
())
{
return
;
}
...
...
spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/Verify.java
View file @
7942d9f7
...
...
@@ -84,7 +84,6 @@ public final class Verify {
return
properties
;
}
public
static
class
ArchiveVerifier
{
private
final
ZipFile
zipFile
;
...
...
spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesBinder.java
View file @
7942d9f7
...
...
@@ -81,8 +81,7 @@ public class PropertySourcesBinder {
}
/**
* Extract the keys using the specified {@code prefix}. The
* prefix won't be included.
* Extract the keys using the specified {@code prefix}. The prefix won't be included.
* <p>
* Any key that starts with the {@code prefix} will be included
* @param prefix the prefix to use
...
...
@@ -119,7 +118,8 @@ public class PropertySourcesBinder {
}
}
private
static
PropertySources
createPropertySources
(
PropertySource
<?>
propertySource
)
{
private
static
PropertySources
createPropertySources
(
PropertySource
<?>
propertySource
)
{
MutablePropertySources
propertySources
=
new
MutablePropertySources
();
propertySources
.
addLast
(
propertySource
);
return
propertySources
;
...
...
spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationProperties.java
View file @
7942d9f7
...
...
@@ -90,7 +90,8 @@ public @interface ConfigurationProperties {
* defined in the environment.
* @return the path (or paths) of resources to bind to
* @see #merge()
* @deprecated configure the environment with those additional locations instead
* @deprecated since 1.4 in favor of configuring the environment directly with
* additional locations
*/
@Deprecated
String
[]
locations
()
default
{};
...
...
@@ -100,7 +101,8 @@ public @interface ConfigurationProperties {
* merged with the default configuration.
* @return the flag value (default true)
* @see #locations()
* @deprecated as {@link #locations()} is deprecated as well
* @deprecated since 1.4 along with {@link #locations()} in favor of configuring the
* environment directly with additional locations
*/
@Deprecated
boolean
merge
()
default
true
;
...
...
spring-boot/src/main/java/org/springframework/boot/context/web/LocalServerPort.java
View file @
7942d9f7
...
...
@@ -16,6 +16,7 @@
package
org
.
springframework
.
boot
.
context
.
web
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
...
...
@@ -24,18 +25,19 @@ import java.lang.annotation.Target;
import
org.springframework.beans.factory.annotation.Value
;
/**
* Annotation at the field or method/constructor parameter level
* that injects the HTTP port that got allocated at runtime.
* <p>
* Convenient meta-annotation replacing {@code @LocalServerPort}.
* Annotation at the field or method/constructor parameter level that injects the HTTP
* port that got allocated at runtime. Privdes a convenient alternative for
* <code>@Value("${local.server.port}")</code>.
*
* @author Anand Shah
* @author Stephane Nicoll
* @since 1.4.0
*/
@
Value
(
"${local.server.port}"
)
@Target
({
ElementType
.
FIELD
,
ElementType
.
METHOD
,
ElementType
.
PARAMETER
,
ElementType
.
ANNOTATION_TYPE
})
@
Target
({
ElementType
.
FIELD
,
ElementType
.
METHOD
,
ElementType
.
PARAMETER
,
ElementType
.
ANNOTATION_TYPE
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Value
(
"${local.server.port}"
)
public
@interface
LocalServerPort
{
}
spring-boot/src/main/java/org/springframework/boot/context/web/ServerPortInfoApplicationContextInitializer.java
View file @
7942d9f7
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
6
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.
...
...
@@ -31,6 +31,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.env.MapPropertySource
;
import
org.springframework.core.env.MutablePropertySources
;
import
org.springframework.core.env.PropertySource
;
import
org.springframework.util.StringUtils
;
/**
...
...
@@ -57,12 +58,14 @@ public class ServerPortInfoApplicationContextInitializer
public
void
initialize
(
ConfigurableApplicationContext
applicationContext
)
{
applicationContext
.
addApplicationListener
(
new
ApplicationListener
<
EmbeddedServletContainerInitializedEvent
>()
{
@Override
public
void
onApplicationEvent
(
EmbeddedServletContainerInitializedEvent
event
)
{
ServerPortInfoApplicationContextInitializer
.
this
.
onApplicationEvent
(
event
);
}
});
}
...
...
@@ -83,26 +86,24 @@ public class ServerPortInfoApplicationContextInitializer
private
void
setPortProperty
(
ApplicationContext
context
,
String
propertyName
,
int
port
)
{
if
(
context
instanceof
ConfigurableApplicationContext
)
{
ConfigurableEnvironment
environment
=
((
ConfigurableApplicationContext
)
context
)
.
getEnvironment
();
MutablePropertySources
sources
=
environment
.
getPropertySources
();
Map
<
String
,
Object
>
map
;
if
(!
sources
.
contains
(
"server.ports"
))
{
map
=
new
HashMap
<
String
,
Object
>();
MapPropertySource
source
=
new
MapPropertySource
(
"server.ports"
,
map
);
sources
.
addFirst
(
source
);
}
else
{
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
value
=
(
Map
<
String
,
Object
>)
sources
.
get
(
"server.ports"
).
getSource
();
map
=
value
;
}
map
.
put
(
propertyName
,
port
);
setPortProperty
(((
ConfigurableApplicationContext
)
context
).
getEnvironment
(),
propertyName
,
port
);
}
if
(
context
.
getParent
()
!=
null
)
{
setPortProperty
(
context
.
getParent
(),
propertyName
,
port
);
}
}
@SuppressWarnings
(
"unchecked"
)
private
void
setPortProperty
(
ConfigurableEnvironment
environment
,
String
propertyName
,
int
port
)
{
MutablePropertySources
sources
=
environment
.
getPropertySources
();
PropertySource
<?>
source
=
sources
.
get
(
"server.ports"
);
if
(
source
==
null
)
{
source
=
new
MapPropertySource
(
"server.ports"
,
new
HashMap
<
String
,
Object
>());
sources
.
addFirst
(
source
);
}
((
Map
<
String
,
Object
>)
source
.
getSource
()).
put
(
propertyName
,
port
);
}
}
spring-boot/src/main/java/org/springframework/boot/info/BuildProperties.java
View file @
7942d9f7
...
...
@@ -72,8 +72,8 @@ public class BuildProperties extends InfoProperties {
/**
* Return the timestamp of the build or {@code null}.
* <p>
* If the original value could not be parsed properly, it is still available with
*
the
{@code time} key.
* If the original value could not be parsed properly, it is still available with
the
* {@code time} key.
* @return the build time
* @see #get(String)
*/
...
...
spring-boot/src/main/java/org/springframework/boot/info/GitProperties.java
View file @
7942d9f7
...
...
@@ -54,16 +54,18 @@ public class GitProperties extends InfoProperties {
* @return the short commit id
*/
public
String
getShortCommitId
()
{
String
commitId
=
getCommitId
();
return
commitId
==
null
?
null
:
(
commitId
.
length
()
>
7
?
commitId
.
substring
(
0
,
7
)
:
commitId
);
String
id
=
getCommitId
();
if
(
id
==
null
)
{
return
null
;
}
return
(
id
.
length
()
>
7
?
id
.
substring
(
0
,
7
)
:
id
);
}
/**
* Return the timestamp of the commit or {@code null}.
* <p>
* If the original value could not be parsed properly, it is still available with
*
the
{@code commit.time} key.
* If the original value could not be parsed properly, it is still available with
the
* {@code commit.time} key.
* @return the commit time
* @see #get(String)
*/
...
...
@@ -72,12 +74,12 @@ public class GitProperties extends InfoProperties {
}
private
static
Properties
processEntries
(
Properties
properties
)
{
coerce
Date
(
properties
,
"commit.time"
);
coerce
Date
(
properties
,
"build.time"
);
coerce
PropertyToEpoch
(
properties
,
"commit.time"
);
coerce
PropertyToEpoch
(
properties
,
"build.time"
);
return
properties
;
}
private
static
void
coerce
Date
(
Properties
properties
,
String
key
)
{
private
static
void
coerce
PropertyToEpoch
(
Properties
properties
,
String
key
)
{
String
value
=
properties
.
getProperty
(
key
);
if
(
value
!=
null
)
{
properties
.
setProperty
(
key
,
coerceToEpoch
(
value
));
...
...
@@ -85,9 +87,9 @@ public class GitProperties extends InfoProperties {
}
/**
* Attempt to convert the specified value to epoch time. Git properties
*
information are known to be specified either as epoch time in seconds
*
or using a specific date
format.
* Attempt to convert the specified value to epoch time. Git properties
information
*
are known to be specified either as epoch time in seconds or using a specific date
* format.
* @param s the value to coerce to
* @return the epoch time in milliseconds or the original value if it couldn't be
* converted
...
...
@@ -110,7 +112,7 @@ public class GitProperties extends InfoProperties {
try
{
return
Long
.
parseLong
(
s
)
*
1000
;
}
catch
(
NumberFormatException
e
)
{
catch
(
NumberFormatException
e
x
)
{
return
null
;
}
}
...
...
spring-boot/src/main/java/org/springframework/boot/info/InfoProperties.java
View file @
7942d9f7
...
...
@@ -17,8 +17,8 @@
package
org
.
springframework
.
boot
.
info
;
import
java.util.Date
;
import
java.util.Enumeration
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.Properties
;
import
org.springframework.core.env.PropertiesPropertySource
;
...
...
@@ -26,8 +26,8 @@ import org.springframework.core.env.PropertySource;
import
org.springframework.util.Assert
;
/**
* Base class for components exposing unstructured data with dedicated methods for
*
well
known keys.
* Base class for components exposing unstructured data with dedicated methods for
well
* known keys.
*
* @author Stephane Nicoll
* @since 1.4.0
...
...
@@ -55,10 +55,8 @@ public class InfoProperties implements Iterable<InfoProperties.Entry> {
}
/**
* Return the value of the specified property as a {@link Date} or {@code null}
* <p>
* Return {@code null} if the value is not a valid {@link Long} representing an
* epoch time.
* Return the value of the specified property as a {@link Date} or {@code null} if the
* value is not a valid {@link Long} representation of an epoch time.
* @param key the id of the property
* @return the property value
*/
...
...
@@ -66,10 +64,9 @@ public class InfoProperties implements Iterable<InfoProperties.Entry> {
String
s
=
get
(
key
);
if
(
s
!=
null
)
{
try
{
long
epoch
=
Long
.
parseLong
(
s
);
return
new
Date
(
epoch
);
return
new
Date
(
Long
.
parseLong
(
s
));
}
catch
(
NumberFormatException
e
)
{
catch
(
NumberFormatException
e
x
)
{
// Not valid epoch time
}
}
...
...
@@ -86,15 +83,42 @@ public class InfoProperties implements Iterable<InfoProperties.Entry> {
* @return a {@link PropertySource}
*/
public
PropertySource
<?>
toPropertySource
()
{
return
new
PropertiesPropertySource
(
getClass
().
getSimpleName
(),
copy
(
this
.
entries
));
return
new
PropertiesPropertySource
(
getClass
().
getSimpleName
(),
copy
(
this
.
entries
));
}
private
static
Properties
copy
(
Properties
properties
)
{
private
Properties
copy
(
Properties
properties
)
{
Properties
copy
=
new
Properties
();
copy
.
putAll
(
properties
);
return
copy
;
}
private
final
class
PropertiesIterator
implements
Iterator
<
Entry
>
{
private
final
Iterator
<
Map
.
Entry
<
Object
,
Object
>>
iterator
;
private
PropertiesIterator
(
Properties
properties
)
{
this
.
iterator
=
properties
.
entrySet
().
iterator
();
}
@Override
public
boolean
hasNext
()
{
return
this
.
iterator
.
hasNext
();
}
@Override
public
Entry
next
()
{
Map
.
Entry
<
Object
,
Object
>
entry
=
this
.
iterator
.
next
();
return
new
Entry
((
String
)
entry
.
getKey
(),
(
String
)
entry
.
getValue
());
}
@Override
public
void
remove
()
{
throw
new
UnsupportedOperationException
(
"InfoProperties are immutable."
);
}
}
/**
* Property entry.
*/
...
...
@@ -119,33 +143,4 @@ public class InfoProperties implements Iterable<InfoProperties.Entry> {
}
private
final
class
PropertiesIterator
implements
Iterator
<
Entry
>
{
private
final
Properties
properties
;
private
final
Enumeration
<
Object
>
keys
;
private
PropertiesIterator
(
Properties
properties
)
{
this
.
properties
=
properties
;
this
.
keys
=
this
.
properties
.
keys
();
}
@Override
public
boolean
hasNext
()
{
return
this
.
keys
.
hasMoreElements
();
}
@Override
public
Entry
next
()
{
String
key
=
(
String
)
this
.
keys
.
nextElement
();
return
new
Entry
(
key
,
this
.
properties
.
getProperty
(
key
));
}
@Override
public
void
remove
()
{
throw
new
UnsupportedOperationException
(
"InfoProperties are immutable."
);
}
}
}
spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java
View file @
7942d9f7
...
...
@@ -47,10 +47,9 @@ import org.springframework.util.StringUtils;
/**
* An {@link ApplicationListener} that configures the {@link LoggingSystem}. If the
* environment contains a {@code logging.config} property it will be used to
* bootstrap the logging system, otherwise a default configuration is used. Regardless,
* logging levels will be customized if the environment contains {@code logging.level.*}
* entries.
* environment contains a {@code logging.config} property it will be used to bootstrap the
* logging system, otherwise a default configuration is used. Regardless, logging levels
* will be customized if the environment contains {@code logging.level.*} entries.
* <p>
* By default, log output is only written to the console. If a log file is required the
* {@code logging.path} and {@code logging.file} properties can be used.
...
...
@@ -295,7 +294,7 @@ public class LoggingApplicationListener implements GenericApplicationListener {
private
boolean
isSet
(
ConfigurableEnvironment
environment
,
String
property
)
{
String
value
=
environment
.
getProperty
(
property
);
return
!(
value
==
null
||
value
.
equals
(
"false"
));
return
(
value
!=
null
&&
!
value
.
equals
(
"false"
));
}
private
void
initializeSystem
(
ConfigurableEnvironment
environment
,
...
...
spring-boot/src/test/java/org/springframework/boot/bind/PropertySourcesBinderTests.java
View file @
7942d9f7
...
...
@@ -37,7 +37,8 @@ public class PropertySourcesBinderTests {
@Test
public
void
extractAllWithPrefix
()
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
env
,
"foo.first=1"
,
"foo.second=2"
);
Map
<
String
,
Object
>
content
=
new
PropertySourcesBinder
(
this
.
env
).
extractAll
(
"foo"
);
Map
<
String
,
Object
>
content
=
new
PropertySourcesBinder
(
this
.
env
)
.
extractAll
(
"foo"
);
assertThat
(
content
.
get
(
"first"
)).
isEqualTo
(
"1"
);
assertThat
(
content
.
get
(
"second"
)).
isEqualTo
(
"2"
);
assertThat
(
content
).
hasSize
(
2
);
...
...
@@ -46,7 +47,8 @@ public class PropertySourcesBinderTests {
@Test
@SuppressWarnings
(
"unchecked"
)
public
void
extractNoPrefix
()
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
env
,
"foo.ctx.first=1"
,
"foo.ctx.second=2"
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
env
,
"foo.ctx.first=1"
,
"foo.ctx.second=2"
);
Map
<
String
,
Object
>
content
=
new
PropertySourcesBinder
(
this
.
env
).
extractAll
(
""
);
assertThat
(
content
.
get
(
"foo"
)).
isInstanceOf
(
Map
.
class
);
Map
<
String
,
Object
>
foo
=
(
Map
<
String
,
Object
>)
content
.
get
(
"foo"
);
...
...
@@ -67,8 +69,9 @@ public class PropertySourcesBinderTests {
assertThat
(
bean
.
getCounter
()).
isEqualTo
(
42
);
}
@SuppressWarnings
(
"unused"
)
private
static
class
TestBean
{
private
String
name
;
private
Integer
counter
;
...
...
spring-boot/src/test/java/org/springframework/boot/context/web/LocalServerPortTests.java
0 → 100644
View file @
7942d9f7
/*
* Copyright 2012-2016 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
context
.
web
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.test.context.TestPropertySource
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link LocalServerPort}.
*
* @author Anand Shah
* @author Phillip Webb
*/
@RunWith
(
SpringRunner
.
class
)
@TestPropertySource
(
properties
=
"local.server.port=8181"
)
public
class
LocalServerPortTests
{
@Value
(
"${local.server.port}"
)
private
String
fromValue
;
@LocalServerPort
private
String
fromAnnotation
;
@Test
public
void
testLocalServerPortAnnotation
()
{
assertThat
(
this
.
fromAnnotation
).
isNotNull
().
isEqualTo
(
this
.
fromValue
);
}
@Configuration
static
class
Config
{
}
}
spring-boot/src/test/java/org/springframework/boot/info/BuildPropertiesTests.java
View file @
7942d9f7
...
...
@@ -31,8 +31,8 @@ public class BuildPropertiesTests {
@Test
public
void
basicInfo
()
{
BuildProperties
properties
=
new
BuildProperties
(
createProperties
(
"
com.example"
,
"
demo"
,
"0.0.1"
,
"2016-03-04T14:36:33+0100"
));
BuildProperties
properties
=
new
BuildProperties
(
createProperties
(
"com.example"
,
"demo"
,
"0.0.1"
,
"2016-03-04T14:36:33+0100"
));
assertThat
(
properties
.
getGroup
()).
isEqualTo
(
"com.example"
);
assertThat
(
properties
.
getArtifact
()).
isEqualTo
(
"demo"
);
assertThat
(
properties
.
getVersion
()).
isEqualTo
(
"0.0.1"
);
...
...
spring-boot/src/test/java/org/springframework/boot/info/GitPropertiesTests.java
View file @
7942d9f7
...
...
@@ -81,7 +81,8 @@ public class GitPropertiesTests {
assertThat
(
properties
.
getShortCommitId
()).
isEqualTo
(
"abc"
);
}
private
static
Properties
createProperties
(
String
branch
,
String
commitId
,
String
commitTime
)
{
private
static
Properties
createProperties
(
String
branch
,
String
commitId
,
String
commitTime
)
{
Properties
properties
=
new
Properties
();
properties
.
put
(
"branch"
,
branch
);
properties
.
put
(
"commit.id"
,
commitId
);
...
...
spring-boot/src/test/java/org/springframework/boot/info/InfoPropertiesTests.java
View file @
7942d9f7
...
...
@@ -86,6 +86,7 @@ public class InfoPropertiesTests {
MyInfoProperties
(
Properties
entries
)
{
super
(
entries
);
}
}
}
spring-boot/src/test/java/org/springframework/boot/testutil/ClassPathExclusions.java
View file @
7942d9f7
...
...
@@ -37,7 +37,6 @@ public @interface ClassPathExclusions {
* path. Matching is performed against an entry's {@link File#getName() file name}.
* For example, to exclude Hibernate Validator from the classpath,
* {@code "hibernate-validator-*.jar"} can be used.
*
* @return the exclusion patterns
*/
String
[]
value
();
...
...
spring-boot/src/test/java/org/springframework/boot/testutil/FilteredClassPathRunner.java
View file @
7942d9f7
...
...
@@ -47,36 +47,15 @@ import org.springframework.util.StringUtils;
*/
public
class
FilteredClassPathRunner
extends
BlockJUnit4ClassRunner
{
public
FilteredClassPathRunner
(
Class
<?>
k
lass
)
throws
InitializationError
{
super
(
k
lass
);
public
FilteredClassPathRunner
(
Class
<?>
testC
lass
)
throws
InitializationError
{
super
(
testC
lass
);
}
@Override
protected
TestClass
createTestClass
(
Class
<?>
testClass
)
{
try
{
final
ClassLoader
classLoader
=
createTestClassLoader
(
testClass
);
return
new
TestClass
(
classLoader
.
loadClass
(
testClass
.
getName
()))
{
@SuppressWarnings
(
"unchecked"
)
@Override
public
List
<
FrameworkMethod
>
getAnnotatedMethods
(
Class
<?
extends
Annotation
>
annotationClass
)
{
List
<
FrameworkMethod
>
methods
=
new
ArrayList
<
FrameworkMethod
>();
try
{
for
(
FrameworkMethod
frameworkMethod
:
super
.
getAnnotatedMethods
(
(
Class
<?
extends
Annotation
>)
classLoader
.
loadClass
(
annotationClass
.
getName
())))
{
methods
.
add
(
new
CustomTcclFrameworkMethod
(
classLoader
,
frameworkMethod
.
getMethod
()));
}
return
methods
;
}
catch
(
ClassNotFoundException
ex
)
{
throw
new
RuntimeException
(
ex
);
}
}
};
ClassLoader
classLoader
=
createTestClassLoader
(
testClass
);
return
new
FilteredTestClass
(
classLoader
,
testClass
.
getName
());
}
catch
(
Exception
ex
)
{
throw
new
IllegalStateException
(
ex
);
...
...
@@ -136,6 +115,9 @@ public class FilteredClassPathRunner extends BlockJUnit4ClassRunner {
return
filteredUrls
.
toArray
(
new
URL
[
filteredUrls
.
size
()]);
}
/**
* Filter for class path entries.
*/
private
static
final
class
ClassPathEntryFilter
{
private
final
List
<
String
>
exclusions
;
...
...
@@ -163,25 +145,75 @@ public class FilteredClassPathRunner extends BlockJUnit4ClassRunner {
}
}
private
static
final
class
CustomTcclFrameworkMethod
extends
FrameworkMethod
{
/**
* Filtered version of JUnit's {@link TestClass}.
*/
private
static
final
class
FilteredTestClass
extends
TestClass
{
private
final
ClassLoader
classLoader
;
FilteredTestClass
(
ClassLoader
classLoader
,
String
testClassName
)
throws
ClassNotFoundException
{
super
(
classLoader
.
loadClass
(
testClassName
));
this
.
classLoader
=
classLoader
;
}
@Override
public
List
<
FrameworkMethod
>
getAnnotatedMethods
(
Class
<?
extends
Annotation
>
annotationClass
)
{
try
{
return
getAnnotatedMethods
(
annotationClass
.
getName
());
}
catch
(
ClassNotFoundException
ex
)
{
throw
new
RuntimeException
(
ex
);
}
}
@SuppressWarnings
(
"unchecked"
)
private
List
<
FrameworkMethod
>
getAnnotatedMethods
(
String
annotationClassName
)
throws
ClassNotFoundException
{
Class
<?
extends
Annotation
>
annotationClass
=
(
Class
<?
extends
Annotation
>)
this
.
classLoader
.
loadClass
(
annotationClassName
);
List
<
FrameworkMethod
>
methods
=
super
.
getAnnotatedMethods
(
annotationClass
);
return
wrapFrameworkMethods
(
methods
);
}
private
List
<
FrameworkMethod
>
wrapFrameworkMethods
(
List
<
FrameworkMethod
>
methods
)
{
List
<
FrameworkMethod
>
wrapped
=
new
ArrayList
<
FrameworkMethod
>(
methods
.
size
());
for
(
FrameworkMethod
frameworkMethod
:
methods
)
{
wrapped
.
add
(
new
FilteredFrameworkMethod
(
this
.
classLoader
,
frameworkMethod
.
getMethod
()));
}
return
wrapped
;
}
}
/**
* Filtered version of JUnit's {@link FrameworkMethod}.
*/
private
static
final
class
FilteredFrameworkMethod
extends
FrameworkMethod
{
private
final
ClassLoader
c
ustomTccl
;
private
final
ClassLoader
c
lassLoader
;
private
CustomTcclFrameworkMethod
(
ClassLoader
customTccl
,
Method
method
)
{
private
FilteredFrameworkMethod
(
ClassLoader
classLoader
,
Method
method
)
{
super
(
method
);
this
.
c
ustomTccl
=
customTccl
;
this
.
c
lassLoader
=
classLoader
;
}
@Override
public
Object
invokeExplosively
(
Object
target
,
Object
...
params
)
throws
Throwable
{
ClassLoader
originalTccl
=
Thread
.
currentThread
().
getContextClassLoader
();
Thread
.
currentThread
().
setContextClassLoader
(
this
.
customTccl
);
ClassLoader
originalClassLoader
=
Thread
.
currentThread
()
.
getContextClassLoader
();
Thread
.
currentThread
().
setContextClassLoader
(
this
.
classLoader
);
try
{
return
super
.
invokeExplosively
(
target
,
params
);
}
finally
{
Thread
.
currentThread
().
setContextClassLoader
(
original
Tccl
);
Thread
.
currentThread
().
setContextClassLoader
(
original
ClassLoader
);
}
}
...
...
spring-boot/src/test/java/org/springframework/boot/testutil/FilteredClassPathRunnerTests.java
View file @
7942d9f7
...
...
@@ -30,18 +30,18 @@ import static org.assertj.core.api.Assertions.assertThat;
@ClassPathExclusions
(
"hibernate-validator-*.jar"
)
public
class
FilteredClassPathRunnerTests
{
private
static
final
String
EXCLUDED_RESOURCE
=
"META-INF/services/"
+
"javax.validation.spi.ValidationProvider"
;
@Test
public
void
entriesAreFilteredFromTestClassClassLoader
()
{
assertThat
(
getClass
().
getClassLoader
()
.
getResource
(
"META-INF/services/javax.validation.spi.ValidationProvider"
))
.
isNull
();
assertThat
(
getClass
().
getClassLoader
().
getResource
(
EXCLUDED_RESOURCE
)).
isNull
();
}
@Test
public
void
entriesAreFilteredFromThreadContextClassLoader
()
{
assertThat
(
Thread
.
currentThread
().
getContextClassLoader
()
.
getResource
(
"META-INF/services/javax.validation.spi.ValidationProvider"
))
.
isNull
();
.
getResource
(
EXCLUDED_RESOURCE
)).
isNull
();
}
}
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