栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Spring Cloud Gateway 替换 Nginx 实战

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring Cloud Gateway 替换 Nginx 实战

一 搭建 server-dataway 微服务 二 引入 pom文件


    
        sdgt_parent
        com.baiyee
        0.0.1-SNAPSHOT
    
    4.0.0

    service_gateway

    
        
            org.springframework.cloud
            spring-cloud-starter-gateway
        

        
        
            com.alibaba.cloud
            spring-cloud-starter-alibaba-nacos-discovery
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
        
        
            
                src/main/java
                
                    ***.properties
                    ***.yml
                    ***.xml
                
                false
            
        
    
三 配置文件
# 服务端口
server.port=8080
# 服务名
spring.application.name=service-gateway

# nacos服务地址
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848

#使用服务发现路由
spring.cloud.gateway.discovery.locator.enabled=true

#设置路由id
spring.cloud.gateway.routes[0].id=service-cmn
#设置路由的uri
spring.cloud.gateway.routes[0].uri=lb://service-cmn
#设置路由断言,代理servicerId为auth-service的/auth/路径
spring.cloud.gateway.routes[0].predicates= Path=/admin/cmn/**
        
#设置路由id
spring.cloud.gateway.routes[1].id=service-obj
#设置路由的uri
spring.cloud.gateway.routes[1].uri=lb://service-obj
#设置路由断言,代理servicerId为auth-service的/auth/路径
spring.cloud.gateway.routes[1].predicates= Path=/admin/**
四 创建启动类
package com.baiyee.sdgt;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication
public class ServerGatewayApplication {


    public static void main(String[] args) {
        SpringApplication.run(ServerGatewayApplication.class, args);
    }
}
五 启动后

 六 改造前端
'use strict'
const merge = require('webpack-merge')
const prodEnv = require('./prod.env')


module.exports = merge(prodEnv, {
  NODE_ENV: '"development"',
  //base_API: '"http://localhost:8201"',  // 医院、商业公司、药房和任务分配的接口
  // base_API: '"http://localhost:8202"', // 数据字典
  //base_API: '"http://localhost:9001"', // nginx
  // base_API: '"https://easy-mock.com/mock/5950a2419adc231f356a6636/vue-admin"',
  base_API: '"http://localhost:8080"'
})
七 测试

所有页面都可以正常显示

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/351509.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号