Browse Source

Fix more Spring Boot related mayhem

pull/227/head
Dave Syer 8 years ago
parent
commit
c3f9b1a821
  1. 52
      pom.xml
  2. 53
      spring-cloud-commons/pom.xml
  3. 3
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/AsyncLoadBalancerAutoConfiguration.java
  4. 67
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/serviceregistry/AbstractAutoServiceRegistration.java
  5. 4
      spring-cloud-context/src/test/java/org/springframework/cloud/autoconfigure/RefreshAutoConfigurationClassPathTests.java

52
pom.xml

@ -23,6 +23,8 @@ @@ -23,6 +23,8 @@
<properties>
<main.basedir>.</main.basedir>
<bintray.package>commons</bintray.package>
<aether.version>1.0.2.v20150114</aether.version>
<maven.version>3.3.9</maven.version>
</properties>
<build>
<plugins>
@ -124,6 +126,56 @@ @@ -124,6 +126,56 @@
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<version>${aether.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-basic</artifactId>
<version>${aether.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-impl</artifactId>
<version>${aether.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-spi</artifactId>
<version>${aether.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-file</artifactId>
<version>${aether.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-http</artifactId>
<version>${aether.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-util</artifactId>
<version>${aether.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<modules>
<module>spring-cloud-commons-dependencies</module>
<module>spring-cloud-context</module>

53
spring-cloud-commons/pom.xml

@ -13,10 +13,6 @@ @@ -13,10 +13,6 @@
<packaging>jar</packaging>
<name>Spring Cloud Commons</name>
<description>Spring Cloud Commons</description>
<properties>
<aether.version>1.0.2.v20150114</aether.version>
<maven.version>3.3.9</maven.version>
</properties>
<build>
<plugins>
<plugin>
@ -33,6 +29,7 @@ @@ -33,6 +29,7 @@
<configuration>
<excludes>
<exclude>**/*.properties</exclude>
<exclude>**/*.jks</exclude>
</excludes>
</configuration>
</plugin>
@ -139,53 +136,5 @@ @@ -139,53 +136,5 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<version>${aether.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-basic</artifactId>
<version>${aether.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-impl</artifactId>
<version>${aether.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-spi</artifactId>
<version>${aether.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-file</artifactId>
<version>${aether.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-http</artifactId>
<version>${aether.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-util</artifactId>
<version>${aether.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

3
spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/AsyncLoadBalancerAutoConfiguration.java

@ -35,11 +35,11 @@ import org.springframework.web.client.AsyncRestTemplate; @@ -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 { @@ -62,7 +62,6 @@ public class AsyncLoadBalancerAutoConfiguration {
}
}
@ConditionalOnBean(LoadBalancerClient.class)
@Configuration
static class LoadBalancerInterceptorConfig {
@Bean

67
spring-cloud-commons/src/main/java/org/springframework/cloud/client/serviceregistry/AbstractAutoServiceRegistration.java

@ -1,20 +1,26 @@ @@ -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; @@ -22,9 +28,10 @@ import java.util.concurrent.atomic.AtomicInteger;
*
* @author Spencer Gibb
*/
@SuppressWarnings("deprecation")
public abstract class AbstractAutoServiceRegistration<R extends Registration> implements AutoServiceRegistration, ApplicationContextAware {
private static final Log logger = LogFactory.getLog(AbstractAutoServiceRegistration.class);
public abstract class AbstractAutoServiceRegistration<R extends Registration>
implements AutoServiceRegistration, ApplicationContextAware {
private static final Log logger = LogFactory
.getLog(AbstractAutoServiceRegistration.class);
private boolean autoStartup = true;
@ -42,6 +49,19 @@ public abstract class AbstractAutoServiceRegistration<R extends Registration> im @@ -42,6 +49,19 @@ public abstract class AbstractAutoServiceRegistration<R extends Registration> 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<R extends Registration> im @@ -71,28 +91,27 @@ public abstract class AbstractAutoServiceRegistration<R extends Registration> 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<R extends Registration> im @@ -101,7 +120,6 @@ public abstract class AbstractAutoServiceRegistration<R extends Registration> im
@Deprecated
protected abstract Object getConfiguration();
/**
* @return true, if this is enabled
*/
@ -140,6 +158,7 @@ public abstract class AbstractAutoServiceRegistration<R extends Registration> im @@ -140,6 +158,7 @@ public abstract class AbstractAutoServiceRegistration<R extends Registration> 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<R extends Registration> im @@ -161,16 +180,6 @@ public abstract class AbstractAutoServiceRegistration<R extends Registration> 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<R> serviceRegistry;
protected AbstractAutoServiceRegistration(ServiceRegistry<R> serviceRegistry) {

4
spring-cloud-context/src/test/java/org/springframework/cloud/autoconfigure/RefreshAutoConfigurationClassPathTests.java

@ -7,7 +7,7 @@ import org.springframework.boot.WebApplicationType; @@ -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; @@ -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 {

Loading…
Cancel
Save