五、Spring Cloud 的 Zuul 网关组件

一、maven pom.xml文件配置


			org.springframework.cloud
			spring-cloud-starter-zuul
		


二、主程序

package com.itmuch.cloud;

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

@EnableZuulProxy
@SpringBootApplication
public class ZuulServiceApplication {

	public static void main(String[] args) {
		SpringApplication.run(ZuulServiceApplication.class, args);
	}
}

三、YML文件配置

server:
  port: 8040
  
spring:
  application:
    name: microservice-gateway-zuul

    
eureka:
  client:
    service-url:
      #将服务注册到集群上
      defaultZone: http://user:password123@peer1:8761/eureka/,http://user:password123@peer2:8762/eureka/

四、访问&测试

访问提供者的地址: http://localhost:8081/get/1
                  http://localhost:8080/get/1
 
消费者访问的地址: http://localhost:8100/eureka/1




始用ZUUL访问:     http://localhost:8040/cloud-service/get/1
                  http://localhost:8040/zuul-consumer/eureka/1

你可能感兴趣的:(Spring,Cloud)