diff --git a/pom.xml b/pom.xml index 1023b238..1a9b86bf 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,8 @@ . commons + 1.0.2.v20150114 + 3.3.9 @@ -124,6 +126,56 @@ + + + org.eclipse.aether + aether-api + ${aether.version} + test + + + org.eclipse.aether + aether-connector-basic + ${aether.version} + test + + + org.eclipse.aether + aether-impl + ${aether.version} + test + + + org.eclipse.aether + aether-spi + ${aether.version} + test + + + org.eclipse.aether + aether-transport-file + ${aether.version} + test + + + org.eclipse.aether + aether-transport-http + ${aether.version} + test + + + org.eclipse.aether + aether-util + ${aether.version} + test + + + org.apache.maven + maven-core + ${maven.version} + test + + spring-cloud-commons-dependencies spring-cloud-context diff --git a/spring-cloud-commons/pom.xml b/spring-cloud-commons/pom.xml index d2e27cf4..8133271e 100644 --- a/spring-cloud-commons/pom.xml +++ b/spring-cloud-commons/pom.xml @@ -13,10 +13,6 @@ jar Spring Cloud Commons Spring Cloud Commons - - 1.0.2.v20150114 - 3.3.9 - @@ -33,6 +29,7 @@ **/*.properties + **/*.jks @@ -139,53 +136,5 @@ spring-boot-starter-test test - - org.eclipse.aether - aether-api - ${aether.version} - test - - - org.eclipse.aether - aether-connector-basic - ${aether.version} - test - - - org.eclipse.aether - aether-impl - ${aether.version} - test - - - org.eclipse.aether - aether-spi - ${aether.version} - test - - - org.eclipse.aether - aether-transport-file - ${aether.version} - test - - - org.eclipse.aether - aether-transport-http - ${aether.version} - test - - - org.eclipse.aether - aether-util - ${aether.version} - test - - - org.apache.maven - maven-core - ${maven.version} - test - diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/AsyncLoadBalancerAutoConfiguration.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/AsyncLoadBalancerAutoConfiguration.java index 2ccef8d4..c6c2e1dd 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/AsyncLoadBalancerAutoConfiguration.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/AsyncLoadBalancerAutoConfiguration.java @@ -35,11 +35,11 @@ import org.springframework.web.client.AsyncRestTemplate; * @author Rob Worsnop */ @Configuration +@ConditionalOnBean(LoadBalancerClient.class) @ConditionalOnClass(AsyncRestTemplate.class) public class AsyncLoadBalancerAutoConfiguration { - @ConditionalOnBean(AsyncRestTemplateCustomizer.class) @Configuration static class AsyncRestTemplateCustomizerConfig { @LoadBalanced @@ -62,7 +62,6 @@ public class AsyncLoadBalancerAutoConfiguration { } } - @ConditionalOnBean(LoadBalancerClient.class) @Configuration static class LoadBalancerInterceptorConfig { @Bean diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/serviceregistry/AbstractAutoServiceRegistration.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/serviceregistry/AbstractAutoServiceRegistration.java index 735144c3..54d900f0 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/serviceregistry/AbstractAutoServiceRegistration.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/serviceregistry/AbstractAutoServiceRegistration.java @@ -1,20 +1,26 @@ package org.springframework.cloud.client.serviceregistry; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +import javax.annotation.PreDestroy; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.beans.BeansException; +import org.springframework.boot.web.context.WebServerInitializedEvent; +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; import org.springframework.cloud.client.discovery.ManagementServerPortUtils; import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; +import org.springframework.context.event.EventListener; import org.springframework.core.env.Environment; -import javax.annotation.PreDestroy; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - /** - * Lifecycle methods that may be useful and common to {@link ServiceRegistry} implementations. + * Lifecycle methods that may be useful and common to {@link ServiceRegistry} + * implementations. * * TODO: document the lifecycle * @@ -22,9 +28,10 @@ import java.util.concurrent.atomic.AtomicInteger; * * @author Spencer Gibb */ -@SuppressWarnings("deprecation") -public abstract class AbstractAutoServiceRegistration implements AutoServiceRegistration, ApplicationContextAware { - private static final Log logger = LogFactory.getLog(AbstractAutoServiceRegistration.class); +public abstract class AbstractAutoServiceRegistration + implements AutoServiceRegistration, ApplicationContextAware { + private static final Log logger = LogFactory + .getLog(AbstractAutoServiceRegistration.class); private boolean autoStartup = true; @@ -42,6 +49,19 @@ public abstract class AbstractAutoServiceRegistration im return context; } + @EventListener(WebServerInitializedEvent.class) + public void bind(WebServerInitializedEvent event) { + ApplicationContext context = event.getApplicationContext(); + if (context instanceof ServletWebServerApplicationContext) { + if ("management".equals( + ((ServletWebServerApplicationContext) context).getNamespace())) { + return; + } + } + this.port.compareAndSet(0, event.getWebServer().getPort()); + this.start(); + } + @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { @@ -71,28 +91,27 @@ public abstract class AbstractAutoServiceRegistration im return; } - /*// only set the port if the nonSecurePort is 0 and this.port != 0 - if (this.port.get() != 0 && getConfiguredPort() == 0) { - setConfiguredPort(this.port.get()); - } // only initialize if nonSecurePort is greater than 0 and it isn't already running // because of containerPortInitializer below - if (!this.running.get() && getConfiguredPort() > 0) { + if (!this.running.get()) { register(); if (shouldRegisterManagement()) { registerManagement(); } - this.context.publishEvent(new InstanceRegisteredEvent<>(this, - getConfiguration())); + this.context.publishEvent( + new InstanceRegisteredEvent<>(this, getConfiguration())); this.running.compareAndSet(false, true); - }*/ + } + } /** - * @return if the management service should be registered with the {@link ServiceRegistry} + * @return if the management service should be registered with the + * {@link ServiceRegistry} */ protected boolean shouldRegisterManagement() { - return getManagementPort() != null && ManagementServerPortUtils.isDifferent(this.context); + return getManagementPort() != null + && ManagementServerPortUtils.isDifferent(this.context); } /** @@ -101,7 +120,6 @@ public abstract class AbstractAutoServiceRegistration im @Deprecated protected abstract Object getConfiguration(); - /** * @return true, if this is enabled */ @@ -140,6 +158,7 @@ public abstract class AbstractAutoServiceRegistration im protected String getAppName() { return this.environment.getProperty("spring.application.name", "application"); } + @PreDestroy public void destroy() { stop(); @@ -161,16 +180,6 @@ public abstract class AbstractAutoServiceRegistration im return 0; } - /*@Deprecated - public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) { - // TODO: take SSL into account - // Don't register the management port as THE port - if (!"management".equals(event.getApplicationContext().getNamespace())) { - this.port.compareAndSet(0, event.getEmbeddedServletContainer().getPort()); - this.start(); - } - }*/ - private ServiceRegistry serviceRegistry; protected AbstractAutoServiceRegistration(ServiceRegistry serviceRegistry) { diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/autoconfigure/RefreshAutoConfigurationClassPathTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/autoconfigure/RefreshAutoConfigurationClassPathTests.java index 32c25128..84f7379f 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/autoconfigure/RefreshAutoConfigurationClassPathTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/autoconfigure/RefreshAutoConfigurationClassPathTests.java @@ -7,7 +7,7 @@ import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.ClassPathExclusions; -import org.springframework.cloud.FilteredClassPathRunner; +import org.springframework.cloud.ModifiedClassPathRunner; import org.springframework.cloud.endpoint.event.RefreshEventListener; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Configuration; @@ -17,7 +17,7 @@ import static org.junit.Assert.assertFalse; /** * @author Spencer Gibb */ -@RunWith(FilteredClassPathRunner.class) +@RunWith(ModifiedClassPathRunner.class) @ClassPathExclusions({"spring-boot-actuator-*.jar", "spring-boot-starter-actuator-*.jar"}) public class RefreshAutoConfigurationClassPathTests {