eureka-service配置
application.yml

#eureka默認情況下,將自己作為客服端進行注冊,因此需要禁用該行為
registerWithEureka: false? #表示是否將自己注冊到Eureka Server上,默認為true
fetchRegistry: false? #表示是否從Eureka Server上獲取注冊信息,默認為true
pom.xml



在pom文件中,重點注意如下依賴:
1.
<parent>
? ? ? ? <groupId>org.springframework.boot</groupId>
? ? ? ? <artifactId>spring-boot-starter-parent</artifactId>
? ? ? ? <version>2.0.2.RELEASE</version>
? ? ? ? <relativePath />
</parent>
若無此依賴,啟動時報錯:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gsonBuilder' defined in class path resource [org/springframework/boot/autoconfigure/gson/GsonAutoConfiguration.class]:Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.google.gson.GsonBuilder]: Factory method 'gsonBuilder' threw exception; nested exception is java.lang.BootstrapMethodError: java.lang.NoSuchMethodError: com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder;
2.
<dependencyManagement>
? ? ? ? <dependencies>
? ? ? ? ? ? <dependency>
? ? ? ? ? ? ? ? <groupId>org.springframework.cloud</groupId>
? ? ? ? ? ? ? ? <artifactId>spring-cloud-dependencies</artifactId>
? ? ? ? ? ? ? ? <version>Finchley.RELEASE</version>
? ? ? ? ? ? ? ? <type>pom</type>
? ? ? ? ? ? ? ? <scope>import</scope>
? ? ? ? ? ? </dependency>
? ? ? ? </dependencies>
</dependencyManagement>
若無此處依賴,啟動該spring-cloud-starter-netflix-eureka-server會報錯:
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost]]
3.
<dependency>
? ? ? ? ? ? <groupId>org.springframework.cloud</groupId>
? ? ? ? ? ? <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
? ? ? ? ? ? <version>2.0.0.RELEASE</version>
</dependency>
該依賴用于配置eureka服務(wù)端。
DiscoveryServiceApplication.java

訪問localhost:8761
