SpringCloud——服务网关(eureka-zuul)

服务网关(zuul)又称路由中心,用来统一访问所有api接口,维护服务。

Spring Cloud Zuul通过与Spring Cloud Eureka的整合,实现了对服务实例的自动化维护,所以在使用服务路由配置的时候,我们不需要向传统路由配置方式那样去指定具体的服务实例地址,只需要通过Ant模式配置文件参数即可

pom.xml


  4.0.0
  com.springcloud.demo
  eureka-zuul
 dev
	jar

	springcloud-eureka-zuul
	Demo Project of Eureka zuul

	
		org.springframework.boot
		spring-boot-starter-parent
		1.5.7.RELEASE
		 
	

	
	    
		com.cc.yonyou.app.zuul.BootMain
		UTF-8
		UTF-8
		1.8
		Dalston.SR4
	

	
		
			org.springframework.cloud
			spring-cloud-starter-eureka
		
		
            org.springframework.cloud
            spring-cloud-starter-zuul
        
        
            org.springframework.boot
            spring-boot-starter-web
        
	
		
		
		
        
            io.springfox
            springfox-swagger2
            2.2.2
        
		
			org.springframework.boot
			spring-boot-starter-test
			test
		
		
		
		
			com.alibaba
			druid
			1.0.20
		
		
			com.alibaba
			fastjson
			1.2.12
		
		
			com.github.pagehelper
			pagehelper
			4.1.6
		
		
			org.springframework.boot  
   		 	spring-boot-starter-redis 
   		 	1.3.8.RELEASE 
		
	

	
		
			
				org.springframework.cloud
				spring-cloud-dependencies
				${spring-cloud.version}
				pom
				import
			
		
	

	
		
			
				org.springframework.boot
				spring-boot-maven-plugin
			
			
            
            org.apache.maven.plugins
            	maven-surefire-plugin
            	
            		true
            	
            
		
	
	

application.properties

#在注册中心显示的名字
spring.application.name=rndealer-eureka-zuul
#端口
server.port= 12001
#禁止在ribbon中使用
ribbon.eureka.enabled: false 
#注册中心的地址
eureka.client.serviceUrl.defaultZone=http://localhost:12000/eureka/
#启用熔断的开关
feign.hystrix.enabled=true

#路由
zuul.routes.user.path=/eureka-server/**
zuul.routes.user.serviceId=eureka-server

BootMain.java

package com.springcloud.demo;

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;

@EnableEurekaClient
@EnableZuulProxy
@SpringBootApplication
public class BootMain {

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

	}

}

 

你可能感兴趣的:(微服务,SpringCloud)