/** * Annotation to enable a DiscoveryClient implementation. * @author Spencer Gibb */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @Import(EnableDiscoveryClientImportSelector.class) public @interfaceEnableDiscoveryClient{
/** * If true, the ServiceRegistry will automatically register the local server. * 如果是真的,那么这个服务注册将自动注册到本地服务 * @return - {@code true} if you want to automatically register. */ booleanautoRegister()defaulttrue;
@Deprecated publicvoidbind(WebServerInitializedEvent event){ ApplicationContext context = event.getApplicationContext(); if (context instanceof ConfigurableWebServerApplicationContext) { if ("management".equals(((ConfigurableWebServerApplicationContext) context) .getServerNamespace())) { return; } } this.port.compareAndSet(0, event.getWebServer().getPort()); this.start(); } .... publicvoidstart(){ if (!isEnabled()) { if (logger.isDebugEnabled()) { logger.debug("Discovery Lifecycle disabled. Not starting"); } return; }
// only initialize if nonSecurePort is greater than 0 and it isn't already running // because of containerPortInitializer below if (!this.running.get()) { this.context.publishEvent( new InstancePreRegisteredEvent(this, getRegistration())); register(); if (shouldRegisterManagement()) { registerManagement(); } this.context.publishEvent( new InstanceRegisteredEvent<>(this, getConfiguration())); this.running.compareAndSet(false, true); }
} /** * Register the local service with the {@link ServiceRegistry}. */ protectedvoidregister(){ this.serviceRegistry.register(getRegistration()); } }