-
The entrance
Activate auto assembly
EurekaServerAutoConfiguration bean in the annotationsCopy the code
-
Interpretation of the
public class EurekaServerInitializerConfiguration
implements ServletContextAware, SmartLifecycle, Ordere
Copy the code
This is the method that started the Eureka program in the class as a whole, but where?
- EurekaServerInitializerConfiguration SmartLifecycle is realized
- Where SmartLifecycle extends Lifecycle, Phased
Overridden and returns true
public void start() { new Thread(new Runnable() { @Override public void run() { try { //TODO: is this class even needed now? eurekaServerBootstrap.contextInitialized(EurekaServerInitializerConfiguration.this.servletContext); log.info("Started Eureka Server"); / / release register event publish (new EurekaRegistryAvailableEvent (getEurekaServerConfig ())); EurekaServerInitializerConfiguration.this.running = true; Publish (new EurekaServerStartedEvent(getEurekaServerConfig())); } catch (Exception ex) { // Help! log.error("Could not initialize Eureka servlet context", ex); } } }).start(); }Copy the code
The eurekaServerBootstrap contextInitialized related code
Public void contextInitialized(ServletContext context) {try {// Initialize the Eureka runtime environment initEurekaEnvironment(); // Initialize the eureka context initEurekaServerContext(); / / this is a configuration item can ignore the reading context. The setAttribute (EurekaServerContext. Class. GetName (), enclosing serverContext); } catch (Throwable e) { log.error("Cannot bootstrap eureka server :", e); throw new RuntimeException("Cannot bootstrap eureka server :", e); }}Copy the code
-
trailer
Next, service synchronization and service culling