spring - spring 请求映射和 url 映射有什么区别?

标签 spring spring-mvc spring-boot

在 Debug模式下阅读我的 spring 启动应用程序的日志后,我偶然发现了这个问题。

启动时,虽然 Spring RequestMappingHandlerMapping 是“在应用程序上下文中查找请求映射”并找到在我的 Controller 上定义的请求映射。后来的 BeanNameUrlHandlerMapping 是“在应用程序上下文中查找 URL 映射”并且无法为我的上下文中定义的每个 bean 找到一个(未标识 URL 路径)

我的问题是,请求映射和 url 映射之间有什么区别,有人可以链接文档来阅读 BeanNameUrlHandlerMapping 的内容吗?在寻找?

最佳答案

RequestMappingHandlerMapping

根据文档,RequestMappingHandlerMapping :

Creates RequestMappingInfo instances from type and method-level @RequestMapping annotations in @Controller classes.



RequestMappingInfo可以用构造函数实例化:
public RequestMappingInfo(String name,
                          PatternsRequestCondition patterns,
                          RequestMethodsRequestCondition methods,
                          ParamsRequestCondition params,
                          HeadersRequestCondition headers,
                          ConsumesRequestCondition consumes,
                          ProducesRequestCondition produces,
                          RequestCondition<?> custom)

并表示具有一组要匹配的条件的请求。

BeanNameUrlHandlerMapping

BeanNameUrlHandlerMapping是一个:

Implementation of the HandlerMapping interface that map from URLs to beans with names that start with a slash ("/"),



并作为 AbstractDetectingUrlHandlerMapping是:

detecting URL mappings for handler beans through introspection of all defined beans in the application context.

关于spring - spring 请求映射和 url 映射有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44158550/

相关文章:

java - 组合@RequestMapping、@RestController 和web.xml 时如何应用绝对路径,为什么我的测试失败?

java - Spring 中哪些类区域作为 bean 加载?

java - Spring 是否允许替换引用 bean 中的属性?

ajax - Spring mvc使用AJAX一次上传多个文件不起作用

使用 Spring Boot 对 Elasticsearch/AWS 进行 Java API 运行状况检查

java - spring-boot 不调用自定义 UserDetailsS​​ervice

spring-boot - img 未使用 Thymeleaf 和 Spring Boot 显示

java - 背景 : url(images/2. png)在 style.css 中不起作用

spring - 如何使用Spring Boot设置SpringFox以显示Rest API的两个(或更多)版本?

java - 自定义 ExceptionMapper 在 Spring + Jersey + Jetty 中不起作用