1     /**
2 * 获取项目所有被注解修饰的url
3 * @param run
4 */
5 public void getAllUrl(ConfigurableApplicationContext run) {
6 //获取restcontroller注解的类名
7 String[] beanNamesForAnnotation = run.getBeanNamesForAnnotation(RestController.class);
8 //获取类对象
9 for (String str : beanNamesForAnnotation) {
10 Object bean = run.getBean(str);
11
12 //处理被AOP关照了的Controller
13 while (AopUtils.isAopProxy(bean)) {
14 try {
15 bean = ((Advised) bean).getTargetSource().getTarget();
16 } catch (Exception e) {
17 throw new RuntimeException("get target bean failed", e);
18 }
19 }
20
21 Class<?> forName = bean.getClass();
22 RequestMapping declaredAnnotation = forName.getAnnotation(RequestMapping.class);
23 if (declaredAnnotation != null) {
24 //获取类URL
25 String urlStarts = declaredAnnotation.value()[0];
26 //处理方法URL
27 if(urlStarts == null) {
28 urlStarts = "/"+str+"/";
29 }
30 if(!urlStarts.startsWith("/")) {//处理前缀
31 urlStarts = "/"+urlStarts;
32 }
33 if(!urlStarts.endsWith("/")) {//处理后缀
34 urlStarts = urlStarts+"/";
35 }
36 for (Method method : forName.getDeclaredMethods()) {
37 //过滤没有添加 @IgnoreLogin的请求
38 IgnoreLogin ignoreLogin = method.getAnnotation(IgnoreLogin.class);
39 if(ignoreLogin == null) {continue; }
40 //获取方法URL
41 String urlEnd = "".intern();
42 for(;;) {// 暂时就这些,需要再加
43 RequestMapping requestMapping = method.getAnnotation(RequestMapping.class);
44 if (requestMapping != null) {
45 urlEnd = requestMapping.value()[0];
46 break;
47 }
48 GetMapping getMapping = method.getAnnotation(GetMapping.class);
49 if (getMapping != null) {
50 urlEnd = getMapping.value()[0];
51 break;
52 }
53 PostMapping postMapping = method.getAnnotation(PostMapping.class);
54 if (postMapping != null) {
55 urlEnd = postMapping.value()[0];
56 break;
57 }
58 PutMapping putMapping = method.getAnnotation(PutMapping.class);
59 if (putMapping != null) {
60 urlEnd = putMapping.value()[0];
61 break;
62 }
63 DeleteMapping deleteMapping = method.getAnnotation(DeleteMapping.class);
64 if (deleteMapping != null) {
65 urlEnd = deleteMapping.value()[0];
66 break;
67 }
68 }
69 //处理方法URL
70 if(urlEnd == null) {
71 urlEnd = method.getName();
72 }
73 if(urlEnd.startsWith("/")) {//处理前缀
74 urlEnd = urlEnd.substring(1);
75 }
76 //处理 urlEnd 的 {} 不考虑 {123}id 的情况
77 if(urlEnd.indexOf("{")>=0) {
78 String[] split = urlEnd.split("/");
79 for (String s : split) {
80 if(s.startsWith("{")) {
81 s = "*";
82 }
83 }
84 urlEnd = String.join("/",split);
85 }
86 //存入请求忽略列表
87 if(StringUtils.isEmpty(properties.getAnonUris())) {
88 properties.setAnonUris(urlStarts+urlEnd);
89 } else {
90 properties.setAnonUris(properties.getAnonUris()+StringConstant.COMMA+urlStarts+urlEnd);
91 }
92 }
93 }
94 }
95 }

代码如下

从上下文中获取所有的原生controller的更多相关文章

  1. 在ASP.NET MVC 中获取当前URL、controller、action 、参数

    URL的获取很简单,ASP.NET通用:[1]获取 完整url (协议名+域名+虚拟目录名+文件名+参数) string url=Request.Url.ToString(); [2]获取 虚拟目录名 ...

  2. 在ASP.NET MVC 中获取当前URL、controller、action

    一.URL的获取很简单,ASP.NET通用: [1]获取 完整url (协议名+域名+虚拟目录名+文件名+参数) string url=Request.Url.ToString(); [2]获取 虚拟 ...

  3. Asp.Net_Mvc_获取当前Url、Controller、Action

    一.URL的获取很简单,ASP.NET通用: [1]获取 完整url (协议名+域名+虚拟目录名+文件名+参数) string url=Request.Url.ToString(); [2]获取 虚拟 ...

  4. 在ASP.NET MVC 中获取当前URL、controller、action(转)

    URL的获取很简单,ASP.NET通用: [1]获取 完整url (协议名+域名+虚拟目录名+文件名+参数) string url=Request.Url.ToString(); [2]获取 虚拟目录 ...

  5. 如何在ASP.NET MVC 中获取当前URL、controller、action

    一.URL的获取很简单,ASP.NET通用: [1]获取 完整url (协议名+域名+虚拟目录名+文件名+参数) string url=Request.Url.ToString(); [2]获取 虚拟 ...

  6. Spring MVC 学习笔记3 - 利用Default Annotation 模式获取请求,使Controller与View对应,并传值。

    1. WEB-INF/web.xml 这里定义了获取请求后,执行的第一步.抓取请求. <servlet> <servlet-name>appServlet</servle ...

  7. SpringMVC项目中获取所有URL到Controller Method的映射

    Spring是一个很好很强大的开源框架,它就像是一个容器,为我们提供了各种Bean组件和服务.对于MVC这部分而言,它里面实现了从Url请求映射控制器方法的逻辑处理,在我们平时的开发工作中并不需要太多 ...

  8. 获取当前最上层controller

    - (UIViewController *)topViewController { UIViewController *resultVC; resultVC = [self _topViewContr ...

  9. 白话学习MVC(五)Controller的激活

    一.概述 在此系列开篇的时候介绍了MVC的生命周期 , 对于请求的处理,都是将相应的类的方法注册到HttpApplication事件中,通过事件的依次执行从而完成对请求的处理.对于MVC来说,请求是先 ...

随机推荐

  1. 在安装pdfplumber时报错 Microsoft Visual C++ 14.0 is required.

    在安装pdfplumber时报下列错误: 解决方法:     更新pip ,因为pip 版本太旧 来自为知笔记(Wiz)

  2. Linux中ssh登陆慢的两种原因

    useDNS配置导致登陆慢 如果ssh server的配置文件(通常是 /etc/ssh/sshd_config )中设置 useDNS yes ,可能会导致 ssh 登陆卡住几十秒.将该配置项设为 ...

  3. Selenium_使用switch_to.alert处理弹窗(14)

    与switch_to.window 和 switch_to.frame 相比,switch_to.alert的alert方法使用了@property 装饰器,所以在使用时alert被当成属性调用. 演 ...

  4. centos7 安装jdk 脚本

    下载安装包 链接:https://pan.baidu.com/s/10-U54WwoEaCC9Afj58owJA 提取码:jdk8 写如脚本 vi ***.sh #!/bin/bash #instal ...

  5. vue重置data

    Object.assign(this.$data, this.$options.data()) 解析:1.Object.assign() 方法用于将所有可枚举属性的值从一个或多个源对象复制到目标对象. ...

  6. Whitelabel Error Page错误原因

    前言: 今天在做项目中遇到了一个问题,项目启动成功,但是前段访问接口始终访问不成功,页面一直在404,百度了一番无非两种解决方案: 一.解决方案 1.项目是boot项目查看启动类的位置是否放置正确 要 ...

  7. 【爬虫】从零开始使用 Scrapy

    一. 概述 最近有一个爬虫相关的需求,需要使用 scrapy 框架来爬取数据,所以学习了一下这个非常强大的爬虫框架,这里将自己的学习过程记录下来,希望对有同样需求的小伙伴提供一些帮助. 本文主要从下面 ...

  8. 《剑指offer》面试题34. 二叉树中和为某一值的路径

    问题描述 输入一棵二叉树和一个整数,打印出二叉树中节点值的和为输入整数的所有路径.从树的根节点开始往下一直到叶节点所经过的节点形成一条路径. 示例: 给定如下二叉树,以及目标和 sum = 22, 5 ...

  9. ComboBox行高

    //行高至少大于20 public static void SetComboBoxLineHeight(ComboBox list, int itemHeight) { list.DropDownSt ...

  10. HashMap和TreeMap的内部结构

    一.HashMap 1.基于哈希表的 Map 接口的实现.此实现提供所有可选的映射操作,并允许使用 null 值和 null 键.(除了非同步和允许使用 null 之外,HashMap 类与 Hash ...