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


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

<!-- 注册中心 -->
<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.properties

 http://账号:密码@eureka-server1:8888/eureka/(网关),(逗号隔开可以有多个网关)http://账号:密码@eureka-server2:8888/eureka/

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

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

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的服务注册监听

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

重启项目看控制台是不是可以加载到eureka

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM