Polish
This commit is contained in:
parent
2ae1435916
commit
7942d9f787
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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}.
|
||||
*
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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 (templateProperties.getReceiveTimeout() != null) {
|
||||
rabbitTemplate.setReceiveTimeout(templateProperties.getReceiveTimeout());
|
||||
}
|
||||
if (template.getReplyTimeout() != null) {
|
||||
rabbitTemplate.setReplyTimeout(template.getReplyTimeout());
|
||||
if (templateProperties.getReplyTimeout() != null) {
|
||||
rabbitTemplate.setReplyTimeout(templateProperties.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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.springframework.data.repository.config.RepositoryConfigurationExtensi
|
|||
* Repositories.
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
* @since 1.4.0
|
||||
*/
|
||||
class CouchbaseRepositoriesRegistrar
|
||||
extends AbstractRepositoryConfigurationSourceSupport {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,4 +43,5 @@ import org.springframework.data.redis.repository.support.RedisRepositoryFactoryB
|
|||
@Import(RedisRepositoriesAutoConfigureRegistrar.class)
|
||||
@AutoConfigureAfter(RedisAutoConfiguration.class)
|
||||
public class RedisRepositoriesAutoConfiguration {
|
||||
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ class RedisRepositoriesAutoConfigureRegistrar
|
|||
|
||||
@EnableRedisRepositories
|
||||
private static class EnableRedisRepositoriesConfiguration {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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", "");
|
||||
|
|
|
@ -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.");
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
protected static class Pool {
|
||||
public static class Pool {
|
||||
|
||||
/**
|
||||
* Whether a PooledConnectionFactory should be created instead of a regular
|
||||
|
@ -147,4 +167,5 @@ public class ActiveMQProperties {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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 {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -59,7 +59,6 @@ public class CouchbaseAutoConfigurationIntegrationTests
|
|||
assertThat(this.context.getBeansOfType(Bucket.class)).hasSize(2);
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class CustomConfiguration {
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.Assume;
|
||||
import org.junit.AssumptionViolatedException;
|
||||
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 environment;
|
||||
|
||||
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.environment, this.cluster);
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
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 getEnv() {
|
||||
return this.env;
|
||||
public CouchbaseEnvironment getCouchbaseEnvironment() {
|
||||
return this.environment;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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.environment = environment;
|
||||
this.cluster = cluster;
|
||||
}
|
||||
|
||||
|
@ -98,10 +101,11 @@ public class CouchbaseTestServer implements TestRule {
|
|||
finally {
|
||||
try {
|
||||
this.cluster.disconnect();
|
||||
this.env.shutdownAsync();
|
||||
this.environment.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");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
RedisAutoConfiguration.class, RedisRepositoriesAutoConfiguration.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();
|
||||
|
|
|
@ -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",
|
||||
"");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ex) {
|
||||
throw new MojoExecutionException(ex.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;
|
||||
}
|
||||
|
|
|
@ -84,7 +84,6 @@ public final class Verify {
|
|||
return properties;
|
||||
}
|
||||
|
||||
|
||||
public static class ArchiveVerifier {
|
||||
|
||||
private final ZipFile zipFile;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
* 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.
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
*/
|
||||
|
|
|
@ -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) {
|
||||
coerceDate(properties, "commit.time");
|
||||
coerceDate(properties, "build.time");
|
||||
coercePropertyToEpoch(properties, "commit.time");
|
||||
coercePropertyToEpoch(properties, "build.time");
|
||||
return properties;
|
||||
}
|
||||
|
||||
private static void coerceDate(Properties properties, String key) {
|
||||
private static void coercePropertyToEpoch(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 ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 ex) {
|
||||
// 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.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* 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 {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -86,6 +86,7 @@ public class InfoPropertiesTests {
|
|||
MyInfoProperties(Properties entries) {
|
||||
super(entries);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -47,36 +47,15 @@ import org.springframework.util.StringUtils;
|
|||
*/
|
||||
public class FilteredClassPathRunner extends BlockJUnit4ClassRunner {
|
||||
|
||||
public FilteredClassPathRunner(Class<?> klass) throws InitializationError {
|
||||
super(klass);
|
||||
public FilteredClassPathRunner(Class<?> testClass) throws InitializationError {
|
||||
super(testClass);
|
||||
}
|
||||
|
||||
@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 customTccl;
|
||||
private final ClassLoader classLoader;
|
||||
|
||||
private CustomTcclFrameworkMethod(ClassLoader customTccl, Method method) {
|
||||
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 classLoader;
|
||||
|
||||
private FilteredFrameworkMethod(ClassLoader classLoader, Method method) {
|
||||
super(method);
|
||||
this.customTccl = customTccl;
|
||||
this.classLoader = 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(originalTccl);
|
||||
Thread.currentThread().setContextClassLoader(originalClassLoader);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue