How to show all available routes in Spring?

℡╲_俬逩灬. 提交于 2019-12-04 17:02:40

问题


How to show all the routes mapped in a spring based application? In Rails this is done using rake routes.

I use two mapping methods of spring to create the URL-mappings:

  • @RequestMapping
  • SimpleUrlHandler

I have used the Unix command grep and cut to get all the mappings of @RequestMapping. I wonder if there is some way I can get these details from the Spring application.


回答1:


If you set the Log4J category for log4j.logger.org.springframework.web to INFO or DEBUG you should see the list of mappings in your server's log (e.g. catalina.out) when your app starts up.

For example:

INFO: DefaultAnnotationHandlerMapping: Mapped URL path [/about] onto handler [org.bozos.songfight.webapp.spring.controller.RootController@6bc947]
INFO: DefaultAnnotationHandlerMapping: Mapped URL path [/about.*] onto handler [org.bozos.songfight.webapp.spring.controller.RootController@6bc947]
INFO: DefaultAnnotationHandlerMapping: Mapped URL path [/about/] onto handler [org.bozos.songfight.webapp.spring.controller.RootController@6bc947]
...
INFO: SimpleUrlHandlerMapping: Mapped URL path [/login] onto handler [org.springframework.web.servlet.mvc.UrlFilenameViewController@4035acf6]



回答2:


If you are using Intellij (ultimate edition), then after you build/run the project, you can view the routes in the bottom toolbar Run -> Endpoints -> Mappings.



来源:https://stackoverflow.com/questions/3686196/how-to-show-all-available-routes-in-spring

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!