Spring-Cloud-Eureka構(gòu)建

最近在學習spring-cloud微服務相關(guān)內(nèi)容,首先對服務治理Eureka了解學習,記錄下學習過程中的內(nèi)容。

一,服務注冊中心

1,Maven依賴,這里使用的是Camden.RELEASE版本

<parent>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-parent</artifactId>
      <version>Camden.RELEASE</version>
      <relativePath/>
  </parent>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-netflix-eureka-server</artifactId>
    </dependency>
  </dependencies>

  <build>
      <plugins>
          <plugin>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-maven-plugin</artifactId>
          </plugin>
      </plugins>
  </build>

2,創(chuàng)建啟動類

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

/**
 * EUREKA SERVER
 * 使用SpringBoot注解快速構(gòu)建
 */
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
    public static void main( String[] args ) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }
}

3,配置注冊中心信息

eureka:
  instance:
    hostname: localhost
    instance-id: ${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}}
  client:
    #是否從注冊中心獲取注冊信息,默認為true
    fetch-registry: false
    #是否將自身注冊到注冊中心,默認為true
    register-with-eureka: false
    #eureka注冊中心地址(/eureka是固定值)
    service-url:
       defaultZone: http://localhost:${server.port}/eureka
spring:
  application:
    name: eureka-server
server:
  port: 8000

這里需要注意的是配置文件使用的是YAML語言,需要注意一些使用規(guī)范:

1.大小寫敏感
2.使用縮進表示層級關(guān)系
3.縮進時不允許使用Tab鍵,只允許使用空格
4.縮進的空格數(shù)目不重要,只要相同層級的元素左側(cè)對齊即可

4,啟動注冊中心
可以直接運行main函數(shù),也可以使用maven命令spring-boot:run
輸出如下信息表示啟動成功:

 .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.0.RELEASE)
省略輸出信息......
2017-08-08 21:02:03.002  INFO 1932 --- [       Thread-9] e.s.EurekaServerInitializerConfiguration : Started Eureka Server
2017-08-08 21:02:03.391  INFO 1932 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8000 (http)
2017-08-08 21:02:03.394  INFO 1932 --- [           main] c.n.e.EurekaDiscoveryClientConfiguration : Updating port to 8000
2017-08-08 21:02:03.426  INFO 1932 --- [           main] c.s.c.eureka.EurekaServerApplication     : Started EurekaServerApplication in 20.1 seconds (JVM running for 39.913)

5,管理頁面

管理頁面.png
管理頁面.png

目前為止,一個Spring-Cloud-Eureka的服務注冊中心就構(gòu)建好了

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容