简体   繁体   English

在Spring中使用自己的处理程序映射时,如何服务资源?

[英]How do I serve resources when using my own handler mapping with Spring?

In my web application, pages are dynamically mapped to urls and pages can be added and removed. 在我的Web应用程序中,页面被动态映射到URL,并且可以添加和删除页面。 Hence, I wrote my own class extending AbstractUrlHttpHandlerMapping and all requests are routed to one handler method. 因此,我编写了自己的扩展AbstractUrlHttpHandlerMapping的类,所有请求都路由到一个处理程序方法。

However, now I don't want resources to be treated the same way, resources should just be returned as usually. 但是,现在我不希望以相同的方式对待资源,应该像往常一样返回资源。 How do I achieve this? 我该如何实现? I tried returning a ResourceHttpRequestHandler for such resources, but I am not sure what to set PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE to. 我尝试为此类资源返回ResourceHttpRequestHandler ,但不确定将PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE设置PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE My attempts ended in an NPE. 我的尝试以NPE结尾。

Is there a better way to return resources while using my own handler mapping? 使用我自己的处理程序映射时,是否有更好的方法返回资源?

I realised this is probably a duplicate of this . 我意识到这可能是一个重复 The solution presented there works for this case as well. 此处介绍的解决方案也适用于这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM