Zuul

1 新建微服务工程 导入须要的依赖java

<dependencies>
  		<!-- zuul路由网关 -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-zuul</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-eureka</artifactId>
		</dependency>
		<!-- actuator监控 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<!-- hystrix容错 -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-hystrix</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-config</artifactId>
		</dependency>
		<!-- 平常标配 -->
		<dependency>
			<groupId>com.shi.springCloud04</groupId>
			<artifactId>springCloud04-core</artifactId>
			<version>${project.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-jetty</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
		</dependency>
		<!-- 热部署插件 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>springloaded</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
		</dependency>
  </dependencies>

2 修改yml文件web

server:
  port: 9527
  
spring:
   application:
    name: zuul-getway-9527
zuul:
  prefix: /shi   #访问前缀
  ignored-services: "*"  #全部真实姓名进行隐藏
  routes:
    mydept.serviceId: SPRINGCLOUD04-PRODECT-8001  #真实访问的服务名称
    mydept.path: /mydept/**    #虚拟访问名称
      
eureka: 
  client: #客户端注册进eureka服务列表内
    service-url: 
      defaultZone: http://eureka9001.com:9001/eureka/,http://eureka9002.com:9002/eureka/,http://eureka9003.com:9003/eureka/

info:
  app.name: zuul-getway-9527
  company.name: com.shi
  build.artifactId: $project.artifactId$
  build.version: $project.version$

3 建立启动类配置启动项spring

package com.shi.zuul;

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

/**
 * 开启服务代理网关配置
 * @author SHF
 * @version 建立时间:2018年12月3日  下午4:16:35
 */
@SpringBootApplication
@EnableZuulProxy
public class SpringZuul_APP_9527 {

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

}

测试: http://localhost:9527/shi/mydept/dept/get/1app

相关文章
相关标签/搜索