SpringCloud实例-搭建服务接口网关四

搭建服务接口网关,接口网关主要解决了服务之间的跨域问题

配置文件:


eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8888/eureka/
server:
  port: 8769
spring:
  application:
    name: eureak-zuul

###当访问路径匹配/api-member/**进入注册中心的eureak-member服务,当访问路径匹配/api-order/**进入注册中心的eureak-order服务###
zuul:
  routes:
    api-a:
      path: /api-member/**
      service-id: eureak-member
    api-b:
      path: /api-order/**
      service-id: eureak-order

启动类:

package com.serverzuul.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;

//开启网关
@EnableZuulProxy
@SpringBootApplication
@EnableEurekaClient
public class ZuulApplication {

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

pom文件:


	4.0.0
	com.serverzuul
	
	service-newzuul
	0.0.1-SNAPSHOT

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

	
		UTF-8
		UTF-8
		1.8
	

	
		
			org.springframework.cloud
			spring-cloud-starter-eureka
		
		
			org.springframework.cloud
			spring-cloud-starter-zuul
		
		
			org.springframework.boot
			spring-boot-starter-web
		

		
			org.springframework.boot
			spring-boot-starter-test
			test
		
	

	
		
			
				org.springframework.cloud
				spring-cloud-dependencies
				Dalston.RC1
				pom
				import
			
		
	

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

	
		
			spring-milestones
			Spring Milestones
			https://repo.spring.io/milestone
			
				false
			
		
	


启动页面:

SpringCloud实例-搭建服务接口网关四_第1张图片

SpringCloud实例-搭建服务接口网关四_第2张图片

你可能感兴趣的:(springCloud)