SpringCloud -- gateway 网关 配置

版权声明:转载请标明出处 https://blog.csdn.net/Joe_Wang1/article/details/82886760

Spring Cloud Gateway

       使用IntelliJIdea创建一个消费者工程, New Project ---> 选中Spring Initializr ---> 设置包名/工程名 ---> 勾选Web、Eureka Discovery、gateway等 ---> 设置存储路径。

 在 入口类中增加@EnableZuulProxy

package com.springcloud.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;


@SpringBootApplication
@EnableEurekaClient
@EnableZuulProxy
public class GatewayApplication {

	public static void main(String[] args) {
		SpringApplication.run(GatewayApplication.class, args);
	}
}
修改配置文件,转发到server1客户端  /resources/public/** 路径下
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8080/eureka/
spring:
  application:
    name: gateway
server:
  port: 8083
zuul:
  routes:
    server1: /resources/public/**

在server1   /resources/public/ 路径下 新建 html,结构如下:

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    我是 server1 来自网关转发
</body>
</html>

启动 Eureka注册中心、server1客户端、gateway网关

可见 访问server1端口时,网关进行了转发!

猜你喜欢

转载自blog.csdn.net/Joe_Wang1/article/details/82886760