eureka在项目中的简单使用配置

1.在pom.xml中增长eureka的相关依赖linux

<!-- 注册中心 -->
<dependency>
   <groupId>com.we.core.eureka</groupId>
   <artifactId>we-core-eureka-client</artifactId>
   <version>1.0.0</version>
   <exclusions>
      <exclusion>
         <groupId>org.springframework</groupId>
         <artifactId>spring-context</artifactId>
      </exclusion>
      <exclusion>
         <groupId>org.springframework</groupId>
         <artifactId>spring-test</artifactId>
      </exclusion>

      <exclusion>
         <groupId>com.fasterxml.jackson.core</groupId>
         <artifactId>jackson-core</artifactId>
      </exclusion>
      <exclusion>
         <groupId>com.fasterxml.jackson.core</groupId>
         <artifactId>jackson-databind</artifactId>
      </exclusion>
      <exclusion>
         <groupId>com.fasterxml.jackson.core</groupId>
         <artifactId>jackson-annotations</artifactId>
      </exclusion>
      <exclusion>
         <groupId>com.fasterxml.jackson.core</groupId>
         <artifactId>jackson-dataformat-xml</artifactId>
      </exclusion>
   </exclusions>
</dependency>

2.增长配置文件在resources下新加eureka-client.propertiesweb

 http://帐号:密码@eureka-server1:8888/eureka/(网关),(逗号隔开能够有多个网关)http://帐号:密码@eureka-server2:8888/eureka/spring

linux中的hosts文件在 etc下 进入hosts配置网关例如 :eureka-server1eureka-server2
服务器

网关须要在linux中 配置hosts路由  (配置网关须要和eureka-client.properties中的映射ip地址保持一致)
spa

eureka.name=QDEDU_ACTIVITY
eureka.port=8080
#客户识别此服务的虚拟主机名,这里指的是eureka服务自己(至关于boot中的serviceId)
eureka.vipAddress=${eureka.name}


#设置为false,由于该配置适用于eureka服务器自己的eureka客户端。
#在eureka服务器中运行的eureka客户端须要链接到其余区域中的服务器。
#对于其余应用程序,不该设置(默认为true),以实现更好的基于区域的负载平衡。
#eureka.preferSameZone=false

#若是要使用基于DNS的查找来肯定其余eureka服务器(请参见下面的示例),请更改此选项
eureka.shouldUseDns=false
eureka.us-east-1.availabilityZones=default
#因为shouldUseDns为false,所以咱们使用如下属性来明确指定到eureka服务器的路由(eureka Server地址)
#也可使用host文件中:机器名映射IP地址,便于往后维护
eureka.serviceUrl.default=http://*****:*****@eureka-server1:8888/eureka/,http://*****:*****@eureka-server2:8888/eureka/(*号表明帐号密码)

 3.在web.xml中增长eureka的服务注册监听code

<!-- eureka服务注册监听器 -->
    <listener>
        <description>eurekaListener</description>
        <listener-class>com.we.core.eureka.client.RegisterEurekaService</listener-class>
    </listener>

重启项目看控制台是否是能够加载到eurekaorm

相关文章
相关标签/搜索