搭建springCloud网关zuul

一.pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.ams.gateway</groupId>
  <artifactId>ams-svc-gateway</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>1.5.10.RELEASE</version>
      <relativePath/>
  </parent>

  <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
     <java.version>1.8</java.version>
  </properties>

  <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-parent</artifactId>
                <!--version>Dalston.SR1</version-->
                <version>Edgware.SR3</version> 
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
   </dependencyManagement>
   
  <dependencies>
        <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-devtools</artifactId>
             <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zuul</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-eureka</artifactId>
       </dependency>
  </dependencies>
  <build>
      <plugins>
         <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
         </plugin>
      </plugins>
  </build>
</project>

二.yml配置

spring:
  application:
    name: gateway
  tomcat: 
    uri-encoding: UTF-8
  http:
    encoding:
      charset: UTF-8
      enabled: true
      force: true
  devtools:
    restart:
      enabled: true
server:
  port: 8443
  ssl: 
    key-store: classpath:keystore.p12
    key-store-password: ams2018
    keyStoreType: PKCS12
    keyAlias: tomcat
http:
  port: 7000
eureka: 
instance:
perferIpAddress: true
instanceId: ${spring.cloud.client.ipAddress}:${server.port} client: registerWithEureka:
true fetchRegistry: true serviceUrl: defaultZone: http://admin:ams2018@127.0.0.1:7001/eureka/ #eureka.instance.preferIpAddress=true #eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${server.port} #hystrix调用方法的超时时间,默认是1000毫秒,如果不调第一次启动会访问会报错,第二中方案是设置不超时hystrix.command.default.execution.timeout.enabled: false #熔断超时 hystrix: command: default: execution: isolation: thread: timeoutInMilliseconds: 60000 #网关配置 zuul: servlet-path: / #解决通过网关上传文件文件名乱码问题 host: connect-timeout-millis: 60000 socket-timeout-millis: 60000 ribbon: eager-load: enabled: true #启动饥饿加载 routes: api-service1: path: /service1/** serviceId: service1 stripPrefix: false api-service2: path: /** serviceId:service2 stripPrefix: false #转发时不忽略前缀

三、启动类

package com;

import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Bean;

@EnableZuulProxy
@SpringCloudApplication
public class Application
{
    public static void main(String[] args)
    {
        new SpringApplicationBuilder(Application.class).web(true).run(args);
    }

}

 

转载于:https://www.cnblogs.com/zincredible/p/9387791.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值