Y9ConsulAutoServiceRegistrationListener
This commit is contained in:
parent
1b47f5a122
commit
b610456eeb
|
@ -0,0 +1,18 @@
|
||||||
|
package net.risesoft.demo.config;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.cloud.client.serviceregistry.Y9ConsulAutoServiceRegistrationListener;
|
||||||
|
import org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistrationListener;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = true)
|
||||||
|
public class Y9Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean(ConsulAutoServiceRegistrationListener.class)
|
||||||
|
public Y9ConsulAutoServiceRegistrationListener y9ConsulAutoServiceRegistrationListener() {
|
||||||
|
return new Y9ConsulAutoServiceRegistrationListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package org.springframework.cloud.client.serviceregistry;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||||
|
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||||
|
import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
|
||||||
|
import org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistration;
|
||||||
|
import org.springframework.context.ApplicationListener;
|
||||||
|
|
||||||
|
public class Y9ConsulAutoServiceRegistrationListener implements ApplicationListener<ApplicationReadyEvent> {
|
||||||
|
@Autowired
|
||||||
|
private ConsulAutoServiceRegistration consulAutoServiceRegistration;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ConsulDiscoveryProperties consulProperties;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ServerProperties serverProperties;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onApplicationEvent(ApplicationReadyEvent event) {
|
||||||
|
// 参考 ConsulAutoServiceRegistrationListener
|
||||||
|
consulAutoServiceRegistration.getPort().compareAndSet(0, serverProperties.getPort());
|
||||||
|
consulAutoServiceRegistration.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -7,7 +7,7 @@ management:
|
||||||
exposure:
|
exposure:
|
||||||
include: '*'
|
include: '*'
|
||||||
server:
|
server:
|
||||||
port: 8081
|
port: 9000
|
||||||
servlet:
|
servlet:
|
||||||
context-path: /demo01-client
|
context-path: /demo01-client
|
||||||
encoding:
|
encoding:
|
||||||
|
|
Loading…
Reference in New Issue