如果不是普通demo,還有別的配置時,須要注意如果服務開不起來可能就是父類依賴中可能會須要<dependencyManagement>這個標籤。java
一、導入依賴spring
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> <version>2.1.2.RELEASE</version> </dependency>
二、配置文件application.ymltomcat
#內置的tomcat服務啓動監聽端口號 server: port: 6002 #EurekaServer配置 eureka: instance: hostname: eureka6002 #EurekaServer的名字 client: register-with-eureka: false #此EurekaServer不在註冊到其餘的註冊中心 fetch-registry: false #不在從其餘中心中心拉取服務器信息 service-url: defaultZone: http://eureka6001.com:6001/eureka #註冊中心訪問地址
---------------------------------------
#內置的tomcat服務啓動監聽端口號
server:
port: 6001
#EurekaServer配置
eureka:
instance:
hostname: eureka6001
client:
register-with-eureka: false #此EurekaServer不在註冊到其餘的註冊中心
fetch-registry: false #不在從其餘中心中心拉取服務器信息
service-url:
defaultZone: http://eureka6002.com:6002/eureka #註冊中心訪問地址
三、主啓動類服務器
@SpringBootApplication //標記這是主啓動類 @EnableEurekaServer //標記這是EurekaServer public class AppStart2 { public static void main(String[] args) { SpringApplication.run(AppStart2.class, args); } }
一、導入依賴,上面的依賴app
二、配置application.yml中添加ide
eureka: client: register-with-eureka: true #容許註冊到EurekaServer fetch-registry: true #從其餘中心中心拉取服務器信息 service-url: defaultZone: http://eureka6002.com:6002/eureka,http://eureka6001.com:6001/eureka #註冊中心訪問地
三、主啓動類微服務
@SpringBootApplication @EnableEurekaClient //標記這是一個Euerka客戶端,必需要寫 public class ProductProvider_8001 { public static void main(String[] args) { SpringApplication.run(ProductProvider_8001.class,args); } }
訪問http://localhost:6001/ 和 http://localhost:6002/ fetch
這就是一個demo,缺點不少,好比:在status下面懸停時,在左下角會可以看到IP。url