一、建立Eureka服务端
1、建立Eureka服务端pom
<?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>org.example</groupId> <artifactId>EurekaServer</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <properties> <spring.version>2.2.4.RELEASE</spring.version> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-parent</artifactId> <version>2.2.4.RELEASE</version> </parent> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>8</source> <target>8</target> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.2.4.RELEASE</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Hoxton.SR7</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <!-- springCloud 配置 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <!-- springCloud注测中心服务 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <!-- <dependency>--> <!-- <groupId>org.springframework.boot</groupId>--> <!-- <artifactId>spring-boot-starter-test</artifactId>--> <!-- <version>${spring.version}</version>--> <!-- <scope>test</scope>--> <!-- </dependency>--> <!-- 新版本的Spring Cloud对熔断器Hystrix有要求,Eureka中必须添加对Hystrix的依赖才可以--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency> </dependencies> </project>
2、启动器
package com.eureka;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
/**
* @name: EurekaServerStarter
* @description: Eureka服务发现模块
* @author: lin
* @version: v1.0
* @create: 2020-12-20 16:28
**/
@EnableEurekaServer
@SpringBootApplication
public class EurekaServerStarter {
public static void main(String[] args) {
SpringApplication.run(EurekaServerStarter.class, args);
}
}
3、配置文件
1 #注册中心服务ID 2 spring.application.name=eureka-server 3 eureka.instance.hostname=localhost 4 #端口号 5 server.port=9999 6 # eureka.client.registerWithEureka :表示是否将自己注册到Eureka Server,默认为true。 7 # 由于当前这个应用就是Eureka Server,故而设为false 8 eureka.client.register-with-eureka=false 9 # eureka.client.fetchRegistry :表示是否从Eureka Server获取注册信息,默认为true。因为这是一个单点的Eureka Server, 10 # 不需要同步其他的Eureka Server节点的数据,故而设为false。 11 eureka.client.fetch-registry=false 12 # eureka.client.serviceUrl.defaultZone :设置与Eureka Server交互的地址,查询服务和注册服务都需要依赖这个地址。默认是 13 eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
4、启动服务端运行
二、建立Eureka网关
待续
springcloud gateway+security+openfeign
原文:https://www.cnblogs.com/Sunlinux0523/p/14351602.html