[英]How to find which method is called when going to route?
I am getting too many redirects error I and want to find in which method this happens.我收到太多重定向错误,我想找出发生这种情况的方法。 The url I am going is
我去的url是
https://localhost:8443/OpenELIS-Global/ https://localhost:8443/OpenELIS-Global/
I tried searching codebase for OpenELIS-Global but I could not find something related with routes.我尝试在代码库中搜索 OpenELIS-Global,但找不到与路线相关的内容。
Also searched for @GetMapping - also nothing with OpenELIS-Global.还搜索了@GetMapping - OpenELIS-Global 也没有。
How do I find which method is called when going to that route?转到该路线时如何找到调用哪个方法?
In symfony can simply use在 symfony 中可以简单地使用
php bin/console debug:router
It is unbelievable if there is no similar command for spring. spring竟然没有类似的命令,简直不敢相信。
Update更新
Base on the answer: spring version 5, as I understand MVC because there are controller files, log framework - I see there is log4j-1.2.8.jar基于答案:spring 版本 5,据我了解 MVC 因为有 controller 个文件,日志框架 - 我看到有 log4j-1.2.8.jar
Update更新
The application I am working on looks like is forked from https://github.com/I-TECH-UW/OpenELIS-Global-2 .我正在处理的应用程序看起来像是从https://github.com/I-TECH-UW/OpenELIS-Global-2分叉出来的。 Just last commit being used is from 2021 if I remember well.
如果我没记错的话,最后一次使用的提交是从 2021 年开始的。
Update更新
Based on Jordi answer I added logging configs.根据 Jordi 的回答,我添加了日志记录配置。 It shows for most routes but for one route - https://localhost:8443/OpenELIS-Global/ which was giving problems (ketp redirecting to itself) and I did not know where to debug it - it still does not show:
它显示了大多数路由,但显示了一条路由 - https://localhost:8443/OpenELIS-Global/ 出现问题(ketp 重定向到自身)并且我不知道在哪里调试它 - 它仍然没有显示:
When going to https://localhost:8443/OpenELIS-Global url, there are redirects去https://localhost:8443/OpenELIS-Global url时,有重定向
as you can see there were 3 requess but only login and home routes shown in log:如您所见,有 3 个请求,但日志中仅显示登录和主页路由:
openelisglobal-webapp | 26 Apr 2022 17:31:55 -- TRACE -- Mapped to org.openelisglobal.login.controller.LoginPageController#showLoginPage(HttpServletRequest, Principal)
openelisglobal-webapp | 26 Apr 2022 17:31:55 -- TRACE -- Mapped to org.openelisglobal.login.controller.LoginPageController#showLoginPage(HttpServletRequest, Principal)
openelisglobal-webapp | 26 Apr 2022 17:31:55 -- TRACE -- Mapped to org.openelisglobal.home.controller.HomeController#showPanelManagement(HttpServletRequest)
openelisglobal-webapp | 26 Apr 2022 17:31:55 -- TRACE -- Mapped to org.openelisglobal.home.controller.HomeController#showPanelManagement(HttpServletRequest)
With another guy I discussed - it was somehow complicated done - the root route compressed in.war file.我和另一个人讨论过——做起来有点复杂——根路由压缩在 .war 文件中。
src/main/resources/log4j2.properties: src/main/resources/log4j2.properties:
loggers=rolling,routes
logger.routes.name=org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
logger.routes.level = trace
logger.routes.appenderRefs = file, console
logger.routes.appenderRef.file.ref = RollingFile
logger.routes.appenderRef.console.ref = STDOUT
Update更新
Added添加
logging.level.org.springframework.web=debug
to src/main/resources/application.properties到 src/main/resources/application.properties
from Antoniossss answer.来自安东尼奥的回答。 Intellij shows that it is unused property.
Intellij 显示它是未使用的属性。
And it shows logs from Jordi config as I understand据我所知,它显示了来自 Jordi 配置的日志
openelisglobal-webapp | 26 Apr 2022 21:56:15 -- TRACE -- Mapped to org.openelisglobal.login.controller.LoginPageController#showLoginPage(HttpServletRequest, Principal)
openelisglobal-webapp | 26 Apr 2022 21:56:15 -- TRACE -- Mapped to org.openelisglobal.login.controller.LoginPageController#showLoginPage(HttpServletRequest, Principal)
openelisglobal-webapp | 26 Apr 2022 21:56:15 -- TRACE -- Mapped to org.openelisglobal.login.controller.LoginPageController#showLoginPage(HttpServletRequest, Principal)
openelisglobal-webapp | 26 Apr 2022 21:56:15 -- TRACE -- Mapped to org.openelisglobal.login.controller.LoginPageController#showLoginPage(HttpServletRequest, Principal)
openelisglobal-webapp | 26 Apr 2022 21:56:15 -- TRACE -- Mapped to org.openelisglobal.login.controller.LoginPageController#showLoginPage(HttpServletRequest, Principal)
openelisglobal-webapp | 26 Apr 2022 21:56:15 -- TRACE -- Mapped to org.openelisglobal.login.controller.LoginPageController#showLoginPage(HttpServletRequest, Principal)
By one hand, there is some additional information that could be useful in order to provide a more concrete answer: Spring Version (5?), assuming Spring MVC, and also the log framework that you are using.一方面,有一些额外的信息可能对提供更具体的答案有用:Spring 版本(5?),假设 Spring MVC,以及您正在使用的日志框架。
By other hand, there are mainly two approaches to analyse routes further than what you can deduce directly looking into your code:另一方面,主要有两种方法可以比直接查看代码更深入地分析路由:
Both approaches are detailed here: How to debug Spring MVC url mapping?此处详细介绍了这两种方法: How to debug Spring MVC url mapping?
It is an old post with some recent updates in which two most voted answers provide details on the commented approaches.这是一篇旧帖子,最近进行了一些更新,其中两个投票最多的答案提供了有关评论方法的详细信息。
According to the additional info provided, it seems clear you are using log4j2.根据提供的附加信息,很明显您正在使用 log4j2。 It is a mavenized project, the maven pom.xml config file contains a log4j2 specific version config (2.17.1).
这是一个 mavenized 项目,maven pom.xml 配置文件包含一个 log4j2 特定版本配置(2.17.1)。 Also, in src/main/resources you can find a log4j2.properties config file.
此外,在 src/main/resources 中,您可以找到一个 log4j2.properties 配置文件。
You can configure there a specific logger, similar to the following config (it has not been tested):您可以在那里配置一个特定的记录器,类似于以下配置(尚未测试):
loggers=rolling,routes
logger.routes.name=org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
logger.routes.level = trace
logger.routes.appenderRefs = file, console
logger.routes.appenderRef.file.ref = RollingFile
logger.routes.appenderRef.console.ref = STDOUT
You can add also a more generic one for org.springframework.web to debug level.您还可以为 org.springframework.web 添加一个更通用的调试级别。
This will probably help, as stated in the referenced post.正如参考帖子中所述,这可能会有所帮助。
I would simply turn on loggin with (application.properties)我会简单地打开登录(application.properties)
logging.level.org.springframework.web=debug
this will disclose some information about existing mappiongs and which handler methods are picked upt to serve incoming requests as well as used response handlers.这将披露有关现有映射的一些信息,以及选择哪些处理程序方法来服务传入请求以及使用的响应处理程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.