中间件(11) : shenyuAPI网关[2]-接口导入

博客介绍了shenyu网关导入接口的开发步骤,包括启动shenyu - admin和shenyu - bootstrap、引入maven依赖、在Controller上添加注解、添加配置、打开http支持、启动导入的工程,最后给出访问地址。主要使用Java语言,涉及中间件相关知识。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考 : apache shenyu网关简单入门 - 请叫我猿叔叔 - 博客园

1.启动shenyu-admin和shenyu-bootstrap

2.引入maven依赖

        <dependency>
            <groupId>org.apache.shenyu</groupId>
            <artifactId>shenyu-spring-boot-starter-client-springmvc</artifactId>
            <version>2.4.3</version>
        </dependency>

        <dependency>
            <groupId>org.apache.shenyu</groupId>
            <artifactId>shenyu-spring-boot-starter-client-common</artifactId>
            <version>2.4.3</version>
        </dependency>

 3.Controller上添加注解

添加注解 @ShenyuSpringMvcClient,path为当前Controller的uri前缀

import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test2/")
@ShenyuSpringMvcClient(path = "/test2/**")
public class HttpTest2Controller {

    @GetMapping("/hello2")
    public String helloHttp() {
        return "hello2 shenyu http";
    }

    @GetMapping("/hello3")
    public String helloHttp3() {
        return "hello3 shenyu http";
    }
}

4.添加配置

shenyu.register.register-type=http
shenyu.register.server-lists=http://localhost:9095
shenyu.register.props.username=admin
shenyu.register.props.password=123456
shenyu.client.http.props.appName=shenyu-test
shenyu.client.http.props.contextPath=/shenyu-test

5.打开http支持

apache shenyu网关简单入门 - 请叫我猿叔叔 - 博客园

6.启动导入的工程

7.访问

http://localhost:9195/shenyu-test/test2/hello3 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值