【问题标题】:How to find the controller mapped to the URL in spring annotations如何在spring注解中找到映射到URL的控制器
【发布时间】:2013-03-17 16:33:17
【问题描述】:

当被要求解决问题时,通过了解代码流,我找到了被点击的 URL,然后我转到映射到该特定 URL 的控制器

我找到了进程very tedious,因为我们有大约 50 个控制器类和更多带有 URL 注释的方法

现在,我在 Eclipse IDE 中使用 search-option 并找到方法注释的 URL 模式

有什么简单的方法,我可以在某某类中获取映射到某某方法的 URL 等信息???

请帮我解决这个问题

【问题讨论】:

  • 我经常认为这是基于注释的网络编程的缺点。我喜欢我的单个 XML 配置文件,至少对于非平凡的控制器分组而言。

标签: spring-mvc spring-webflow spring-annotations


【解决方案1】:

如果您使用的是 Spring MVC 3.x,请查看链接。

Endpoint documentation controller for Spring MVC 3.x

【讨论】:

  • 有没有关于如何在项目中使用它的示例?
  • 对于 spring 3.0 有没有办法实现这个? RequestMappingHandlerMapping 类仅从 3.1 开始。如何在 3.0 中达到同样的效果??
【解决方案2】:

也许Reflections 库可以提供帮助:

Reflections reflections = new Reflections("my.package", 
      new TypeAnnotationsScanner(), new MethodAnnotationsScanner());

Set<Class<?>> controllers = reflections.getTypesAnnotatedWith(Controller.class);

Set<Method> requestMappings = reflections.getMethodsAnnotatedWith(RequestMapping.class);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-25
    • 1970-01-01
    • 1970-01-01
    • 2015-09-05
    • 2012-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多