如何正确理解和应用Spring Cloud Netflix中的Eureka服务端服务发现功能?

本节描述了如何设置Eureka服务器。

1.如何包含Eureka服务器

要在您的项目中包含Eureka Server,请使用组ID为org.springframework.cloud和Artifact ID为spring-cloud-starter-netflix-eureka-server的starter。有关如何使用当前的Spring Cloud版本设置构建系统的详细信息,请参阅Spring Cloud项目页面。

注意

如果您的项目已经使用Thymeleaf作为模板引擎,Eureka服务器的Freemarker模板可能无法正确加载。在这种情况下,需要手动配置模板加载器:

application.yml

spring:
  freemarker:
    template-loader-path: classpath:/templates/
    prefer-file-system-access: false

2.如何运行Eureka服务器

以下示例展示了一个最简单的Eureka服务器:

@SpringBootApplication
@EnableEurekaServer
public class Application {

    public static void main(String[] args) {
        new SpringApplicationBuilder(Application.class).web(true).run(args);
    }

}

该服务器有一个带有用户界面和HTTP API端点的主页,用于常规的Eureka功能,位于/eureka/*路径下。

以下链接提供了一些关于Eureka的背景阅读:flux capacitor和go

你可能感兴趣的:(开启无限可能:探索Spring,Boot的奇妙世界,eureka,服务发现,spring,cloud,java,spring,boot)