Spring RequestMapping antmatcher 忽略 URL

Spring RequestMapping antmatcher ignore URL

我有一个相当简单的 RequestMapping,它从 ui-router:

转发 urls
@RequestMapping(value = "/**/{path:[^\.]*}")
    public String redirect(@PathVariable("path") String path) {
        // Forward to home page so that route is preserved.
        return "forward:/";
    }

这是为了让一切都能与我的 SAML IDP 配合使用。但是,我也有一个正在创建的 websocket,我不想想通过这里。 websocket url 的形式为:

/ws/**

我一直在尝试使用正则表达式来忽略其中包含 'ws' 的 url,但我运气不佳。我已经非常接近了,但是我尝试过的任何事情都无法让我得到我想要的东西。有什么办法可以将我的 antmatcher 中的第一个 /** 与正则表达式结合起来忽略我想要的吗?我可以编写正则表达式没问题,我只是不确定如何将它合并到 antmatcher 中。

tldr:我需要匹配的蚂蚁匹配器:

/bbs/index /邮箱 等...

但不是:

/ws/info

您可以尝试将 antMatchers 保留为默认值并尝试使用两种不同的 RequestMappings,其中一种用于 /**,另一种用于 /ws/**

对于 WS 请求,使用类似的东西:

@RequestMapping(value = "/ws/**/{path:[^\.]*}")
    public String wsHandling(@PathVariable("path") String path) {
        // Do some other stuff
        return null;
    }

对于其余的请求,请使用类似的内容:

@RequestMapping(value = "/**/{path:[^\.]*}")
    public String redirect(@PathVariable("path") String path) {
        // Forward to home page so that route is preserved.
        return "forward:/";
    }

我想到了一个更简单的解决方案。我没有尝试重新设计 antmatcher,而是在我所有的 ui-router state url 前加上 'zfgcui' 前缀。我的 antmatcher 现在看起来像:

/zfgcui/**/{path:[^\.]*}

现在忽略 ws 端点并继续仅转发 ui-路由器端点。这要简单得多,实施起来也不那么令人沮丧