gpt4 book ai didi

spring-mvc - 如何在 Spring Boot 中调试 MVC Controller URL 映射?

转载 作者:行者123 更新时间:2023-11-28 21:57:38 25 4
gpt4 key购买 nike

我有一个运行 Kafka 和 JPA 的 Spring Boot 应用程序。我想添加一个管理页面,所以首先添加“spring-boot-starter-web”并添加 Controller 类。但是,当我启动我的应用程序时,我可以看到 Tomcat 服务器已经启动并且 dispatcherServlet 已初始化。

2018-04-13 18:25:29.495  INFO 5512 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$f5f4a697] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 
2018-04-13 18:25:30.584 INFO 5512 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2018-04-13 18:25:30.604 INFO 5512 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-04-13 18:25:30.607 INFO 5512 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.27
2018-04-13 18:25:33.052 INFO 5512 --- [ost-startStop-1] org.apache.jasper.servlet.TldScanner : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded
JARs during scanning can improve startup time and JSP compilation time.
2018-04-13 18:25:33.384 INFO 5512 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-04-13 18:25:33.384 DEBUG 5512 --- [ost-startStop-1] o.s.web.context.ContextLoader : Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]
2018-04-13 18:25:33.385 INFO 5512 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization comp
leted in 6776 ms
2018-04-13 18:25:33.761 INFO 5512 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2018-04-13 18:25:33.768 INFO 5512 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'metricsFilter' to: [/*]

但我看不到 Controller 类与 handlerMapping 映射。来电 http://localhost:8080只给我一个服务器不可用的错误。

我该如何调试它?我已经检查了以下内容:

  1. Controller 类位于主 Application.java 的子文件夹中文件。
  2. Controller 有@Controller 注释。该包中的其他@Components 正在 Autowiring ,所以我确定该文件夹是已扫描。
  3. 我在主类中扩展了 SpringBootServletInitializer 类。
  4. 主类中有如下注解-@SpringBootApplication@Import(PersistenceConfig.class), @EnableKafka, @EnableCaching, @EnableWebMvc,@EnableAutoConfiguration(exclude = { KafkaAutoConfiguration.class })这里的 PersistenceConfig 是我自己的类。

有没有办法找出为什么 Controller 类没有被 MVC 添加到 URL 映射?

我不能分享代码,因为它不是公开的。感谢您对此进行调查。

最佳答案

Is there a way to find out why the Controller classes are not being added to URL mapping by the MVC?

总是很难找出为什么某些事情没有发生(除非它阻止启动),但 Tomcat 中有一个配置项可能会派上用场来调试这个问题:

设置logEffectiveWebXml="true" on your context并在您的日志中查看有效的 web.xml - 从那里您应该能够确定 URL 处理是否有线,或者可能重载或以其他方式被抢占。

关于spring-mvc - 如何在 Spring Boot 中调试 MVC Controller URL 映射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49827060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com