动态创建Requestmapping 和 Gateway HandlerMapping 有差别
This commit is contained in:
parent
9be72ebe6a
commit
ae00f75cd1
|
@ -13,8 +13,10 @@ import org.apache.dubbo.config.ReferenceConfig;
|
|||
import org.apache.dubbo.rpc.service.GenericService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.cloud.gateway.filter.FilterDefinition;
|
||||
import org.springframework.cloud.gateway.filter.NettyWriteResponseFilter;
|
||||
import org.springframework.cloud.gateway.handler.RoutePredicateHandlerMapping;
|
||||
import org.springframework.cloud.gateway.handler.predicate.PredicateDefinition;
|
||||
import org.springframework.cloud.gateway.route.RouteDefinition;
|
||||
import org.springframework.cloud.gateway.route.RouteDefinitionLocator;
|
||||
|
@ -25,6 +27,7 @@ import org.springframework.stereotype.Controller;
|
|||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.reactive.config.WebFluxConfigurationSupport;
|
||||
import org.springframework.web.reactive.result.method.AbstractHandlerMethodMapping;
|
||||
import org.springframework.web.reactive.result.method.RequestMappingInfo;
|
||||
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
@ -167,15 +170,20 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||
private void createHttp2Dubbo(Map<String, Object> configDubbo) {
|
||||
|
||||
try {
|
||||
RequestMappingHandlerMapping requestMapping = (RequestMappingHandlerMapping) applicationContext.getBean("requestMappingHandlerMapping");
|
||||
|
||||
// Method targetMethod = ReflectionUtils.findMethod(Http2Dubbo.class, "H2DTest", HttpServerRequest.class, HttpServerResponse.class); // 找到处理该路由的方法
|
||||
requestMapping.registerMapping(RequestMappingInfo.paths("/test/xixi").methods(RequestMethod.POST).build(),
|
||||
http2Dubbo, Http2Dubbo.class.getDeclaredMethod("H2DTest"));
|
||||
// RequestMappingHandlerMapping requestMapping = (RequestMappingHandlerMapping) applicationContext
|
||||
// .getBean("requestMappingHandlerMapping");
|
||||
|
||||
// // Method targetMethod = ReflectionUtils.findMethod(Http2Dubbo.class, "H2DTest",
|
||||
// // HttpServerRequest.class, HttpServerResponse.class); // 找到处理该路由的方法
|
||||
|
||||
// requestMapping.registerMapping(RequestMappingInfo.paths("/test/xixi").methods(RequestMethod.POST).build(),
|
||||
// http2Dubbo, Http2Dubbo.class.getDeclaredMethod("H2DTest"));
|
||||
|
||||
// 引用远程服务
|
||||
// try {
|
||||
// ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>(); // 该实例很重量,里面封装了所有与注册中心及服务提供方连接,请缓存
|
||||
// ReferenceConfig<GenericService> reference = new
|
||||
// ReferenceConfig<GenericService>(); // 该实例很重量,里面封装了所有与注册中心及服务提供方连接,请缓存
|
||||
|
||||
// reference.setInterface("com.xxx.XxxService"); // 弱类型接口名
|
||||
// reference.setVersion("2.0.0");
|
||||
|
|
|
@ -3,6 +3,7 @@ package cn.ecpark.service.usergw.impl.http;
|
|||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
@ -10,6 +11,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
* Http2Dubbo
|
||||
*/
|
||||
@Controller
|
||||
@RestController
|
||||
public class Http2Dubbo {
|
||||
|
||||
|
||||
|
@ -17,7 +19,13 @@ public class Http2Dubbo {
|
|||
public String H2DTest() {
|
||||
|
||||
//Do clever stuff here
|
||||
return "123";
|
||||
return "H2DTest";
|
||||
// return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/test/fuck")
|
||||
public String fuck() {
|
||||
return "fuck";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user