参考 : 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网关简单入门 - 请叫我猿叔叔 - 博客园