使用SpringBoot获取所有接口的路由
作者:情陌人灬已不在 时间:2021-08-29 22:28:34
SpringBoot获取所有接口的路由
@Autowired
WebApplicationContext applicationContext;
@RequestMapping(value = "v1/getAllUrl", method = RequestMethod.POST)
public Object getAllUrl() {
RequestMappingHandlerMapping mapping = applicationContext.getBean(RequestMappingHandlerMapping.class);
// 获取url与类和方法的对应信息
Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
// List<String> urlList = new ArrayList<>();
// for (RequestMappingInfo info : map.keySet()) {
// // 获取url的Set集合,一个方法可能对应多个url
// Set<String> patterns = info.getPatternsCondition().getPatterns();
//
// for (String url : patterns) {
// urlList.add(url);
// }
// }
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
for (Entry<RequestMappingInfo, HandlerMethod> m : map.entrySet()) {
Map<String, String> map1 = new HashMap<String, String>();
RequestMappingInfo info = m.getKey();
HandlerMethod method = m.getValue();
PatternsRequestCondition p = info.getPatternsCondition();
for (String url : p.getPatterns()) {
map1.put("url", url);
}
map1.put("className", method.getMethod().getDeclaringClass().getName()); // 类名
map1.put("method", method.getMethod().getName()); // 方法名
RequestMethodsRequestCondition methodsCondition = info.getMethodsCondition();
for (RequestMethod requestMethod : methodsCondition.getMethods()) {
map1.put("type", requestMethod.toString());
}
list.add(map1);
}
Springboot部分路由生效
问题记录
项目新增接口"foo",始终不生效,经排查发现controller层的@RequestMaping(value=“test”)统一加了基础路径"test",我新增的接口注解为@PostMappinp(“test/foo),导致生成的路由为"test/test/foo”, 调用地址为"test/foo",所以报了404。
来源:https://www.cnblogs.com/deityjian/p/12533302.html
标签:SpringBoot,接口,路由
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SpringBoot 嵌入式web容器的启动原理详解
2021-12-29 23:23:14
![](https://img.aspxhome.com/file/2023/8/64908_0s.png)
SpringDataJPA在Entity中常用的注解介绍
2023-11-27 09:40:36
Java毕业设计实战之校园一卡通系统的实现
2022-11-26 06:32:56
![](https://img.aspxhome.com/file/2023/1/72521_0s.jpg)
浅谈java安全编码指南之死锁dead lock
2023-06-22 04:49:19
J2ee 高并发情况下监听器实例详解
2022-12-26 05:47:43
C# 通过ServiceStack 操作Redis
2023-12-13 06:18:01
![](https://img.aspxhome.com/file/2023/2/80022_0s.png)
Java中JMM与volatile关键字的学习
2022-03-24 00:12:00
![](https://img.aspxhome.com/file/2023/2/62202_0s.png)
C# XmlDocument操作XML案例详解
2021-11-23 04:00:01
Java运行时环境之ClassLoader类加载机制详解
2022-07-18 04:54:05
![](https://img.aspxhome.com/file/2023/5/75675_0s.jpg)
Java设计模式之命令模式(Command模式)介绍
2021-12-02 01:01:02
Android中TimePicker与DatePicker时间日期选择组件的使用实例
2023-08-07 01:35:15
![](https://img.aspxhome.com/file/2023/0/84740_0s.jpg)
MyBatis动态SQL表达式详解
2023-11-29 00:42:36
Java基础知识之CharArrayReader流的使用
2023-02-12 10:40:29
![](https://img.aspxhome.com/file/2023/0/61010_0s.png)
详解Spring缓存注解@Cacheable,@CachePut , @CacheEvict使用
2021-11-18 12:18:05
C#下载歌词文件的同步和异步方法
2023-04-11 22:46:49
![](https://img.aspxhome.com/file/2023/4/77304_0s.jpg)
c#使用windows服务更新站点地图的详细示例
2021-07-24 10:45:52
![](https://img.aspxhome.com/file/2023/2/80102_0s.png)
Java中常见的对象转换工具
2023-12-14 19:23:16
![](https://img.aspxhome.com/file/2023/6/71886_0s.webp)
flutter实现appbar下选项卡切换
2023-06-21 13:35:24
![](https://img.aspxhome.com/file/2023/3/87313_0s.gif)
关于springboot响应式编程整合webFlux的问题
2023-12-07 07:25:55
![](https://img.aspxhome.com/file/2023/0/68710_0s.png)
java实现纸牌游戏之小猫钓鱼算法
2021-08-11 22:57:00