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

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

1.启动shenyu-admin和shenyu-bootstrap

2.引入maven依赖

        
            org.apache.shenyu
            shenyu-spring-boot-starter-client-springmvc
            2.4.3
        

        
            org.apache.shenyu
            shenyu-spring-boot-starter-client-common
            2.4.3
        

 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 

你可能感兴趣的:(中间件,中间件,java,开发语言,shenyu导入接口)