消費者模塊指的是【基礎數據項目】【用戶項目】【訂單項目】【支付項目】,能夠理解成spring cloud的一個客戶端,而eureka是一個服務端,client是服務端進行註冊服務。java
eureka統一管理這些服務。web
1.建立訂單項目spring
2.選擇組件apache
3.pom文件app
主要是spring-cloud-starter-netflix-eureka-client,表示是一個spring cloud的一個客戶端,會想eureka註冊。maven
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.cohesion</groupId> <artifactId>spring-cloud-order</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>spring-cloud-order</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <spring-cloud.version>Finchley.RELEASE</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
4.配置主類spring-boot
package com.cohesion; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication @EnableEurekaClient//表示本身是spring cloud的客戶端 會想eureka註冊 public class SpringCloudOrderApplication { public static void main(String[] args) { SpringApplication.run(SpringCloudOrderApplication.class, args); } }
5.配置application.yml文件ui
server: port: 8081 spring: application: name: service-order eureka: client: serviceUrl: defaultZone: http://localhost:8080/eureka/
6.啓動Spring Cloud Client【訂單項目】 8081端口服務spa
7.啓動後查看註冊中心是否已經有這個服務.net
能夠看到服務已經註冊到註冊中心