2010-09-10 52 views
6

如何显示在基于弹簧的应用程序中映射的所有路线?在Rails中,这是使用rake路由完成的。如何在Spring中显示所有可用路线?

我用春天的两个映射方法来创建网址的映射:

  • @RequestMapping
  • SimpleUrlHandler

我已经使用了Unix命令grepcut获得的所有映射@RequestMapping。我想知道是否有某种方式可以从Spring应用程序中获取这些细节。

回答

5

如果设置Log4J的类别log4j.logger.org.springframework.webINFODEBUG你应该看到映射列表在你的服务器的日志(例如catalina.out)当你的应用程序启动。

例如:

INFO: DefaultAnnotationHandlerMapping: Mapped URL path [/about] onto handler [[email protected]47] 
INFO: DefaultAnnotationHandlerMapping: Mapped URL path [/about.*] onto handler [[email protected]47] 
INFO: DefaultAnnotationHandlerMapping: Mapped URL path [/about/] onto handler [[email protected]47] 
... 
INFO: SimpleUrlHandlerMapping: Mapped URL path [/login] onto handler [[email protected]35acf6] 
0

如果您使用的是IntelliJ(终极版),那么你建立后/运行项目,可以在底部工具栏Run在查看路线 - >Endpoints - >Mappings

enter image description here