support random server.port
fixes gh-11
This commit is contained in:
@@ -43,11 +43,6 @@
|
||||
<artifactId>spring-cloud-zookeeper-discovery</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper-bus</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
||||
@@ -3,16 +3,13 @@ package org.springframework.cloud.zookeeper.sample;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.bind.RelaxedPropertyResolver;
|
||||
import org.springframework.cloud.bus.jackson.SubtypeModule;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
|
||||
import org.springframework.cloud.zookeeper.bus.SimpleRemoteEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -27,18 +24,19 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@EnableDiscoveryClient
|
||||
@RestController
|
||||
@Slf4j
|
||||
public class SampleApplication implements ApplicationListener<SimpleRemoteEvent> {
|
||||
public class SampleApplication {
|
||||
|
||||
public static final String CLIENT_NAME = "testZookeeperApp";
|
||||
@Value("${spring.application.name:testZookeeperApp}")
|
||||
private String appName;
|
||||
|
||||
@Autowired
|
||||
LoadBalancerClient loadBalancer;
|
||||
private LoadBalancerClient loadBalancer;
|
||||
|
||||
@Autowired
|
||||
Environment env;
|
||||
private Environment env;
|
||||
|
||||
@Autowired(required = false)
|
||||
RelaxedPropertyResolver resolver;
|
||||
private RelaxedPropertyResolver resolver;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SampleApplication.class, args);
|
||||
@@ -46,7 +44,7 @@ public class SampleApplication implements ApplicationListener<SimpleRemoteEvent>
|
||||
|
||||
@RequestMapping("/")
|
||||
public ServiceInstance lb() {
|
||||
return loadBalancer.choose(CLIENT_NAME);
|
||||
return loadBalancer.choose(appName);
|
||||
}
|
||||
|
||||
@RequestMapping("/myenv")
|
||||
@@ -54,14 +52,4 @@ public class SampleApplication implements ApplicationListener<SimpleRemoteEvent>
|
||||
String property = new RelaxedPropertyResolver(env).getProperty(prop, "Not Found");
|
||||
return property;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SubtypeModule sampleSubtypeModule() {
|
||||
return new SubtypeModule(SimpleRemoteEvent.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(SimpleRemoteEvent event) {
|
||||
log.info("Received event: {}", event);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user