在 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/