Spring Cloud系列 Spring Cloud Zuul API网关服务

 Spring Cloud Zuul为服务添加网关服务,网关作为服务的统一入口。

1.项目结构如下:

Spring Cloud系列 Spring Cloud Zuul API网关服务_第1张图片

2.引入jar包pom.xml



	4.0.0
	
		org.springframework.boot
		spring-boot-starter-parent
		2.0.0.RELEASE
		 
	
	com.goodluck
	api-gateway
	0.0.1-SNAPSHOT
	api-gateway
	Demo project for Spring Boot

	
		1.8
	

	
		
			org.springframework.boot
			spring-boot-starter-web
		

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

		
		
			org.springframework.cloud
			spring-cloud-starter-netflix-eureka-client
		

		
			org.springframework.boot
			spring-boot-starter-test
			test
			
				
					org.junit.vintage
					junit-vintage-engine
				
			
		
	

	
	
		
			
				org.springframework.cloud
				spring-cloud-dependencies
				Finchley.RELEASE
				pom
				import
			
		
	

	
		
			
				org.springframework.boot
				spring-boot-maven-plugin
			
		
	


3.添加配置application.properties

spring.application.name=api-gateway
server.port=5555

zuul.routes.outp-cis-api.path=/outp-cis-api/**
zuul.routes.outp-cis-api.sensitiveHeaders=true
zuul.routes.outp-cis-api.serviceId=outp-cis-api


eureka.client.service-url.defaultZone=http://peer1:1111/eureka/,http://peer2:1112/eureka/

 4.启动类添加注解

package com.goodluck;

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

@EnableZuulProxy
@SpringBootApplication
public class ApiGatewayApplication {

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

}

5.启动服务,浏览器中输入:http://localhost:5555/outp-cis-api/feign-consumer。如下图显示正确搭建

Spring Cloud系列 Spring Cloud Zuul API网关服务_第2张图片

你可能感兴趣的:(Spring Cloud系列 Spring Cloud Zuul API网关服务)