eureka在專案中的簡單使用配置
阿新 • • 發佈:2019-05-21
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-server1,eureka-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
&n