V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
BraveXaiver
V2EX  ›  问与答

能复用 Spring 中做 URI 匹配的轮子吗?该怎么做呢?

  •  
  •   BraveXaiver · Oct 26, 2024 · 1376 views
    This topic created in 551 days ago, the information mentioned may be changed or developed.
    是这样的,我正在给 team 开发一个各个 spring 服务都会引入的公共 tookit ,现在打算实现一个 spring interceptor 并在其中实现一些功能,但是呢可以通过配置 URI 去排除一些 API ,使得针对那些 API 该功能不工作。

    那这里就来了一个匹配 URI 的需要,特别是我们的 URI 还可能用到 /uri/address/{accountId} 这样的 Path Parameter ,肯定不应该手写而应该复用 Spring 或者说 Spring Web 的工具。

    但是 Spring 的实现该怎么去利用呢? Spring 的实现是静态工具类?是 Spring Bean ?请教一下大家。

    多谢!
    4 replies    2024-10-27 12:59:04 +08:00
    bxb100
        2
    bxb100  
       Oct 26, 2024
    没必要想太多, 这些应该由调用方自己决定, 你只要 public func 就行了
    itechify
        3
    itechify  
    PRO
       Oct 26, 2024   ❤️ 1
    做过网关白名单,用的这个类 AntPathMatcher ,我记得是线程安全的,作为工具的静态属性,可以复用
    VeryZero
        4
    VeryZero  
       Oct 27, 2024   ❤️ 1
    org.springframework.util.AntPathMatcher#match
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2413 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 01:09 · PVG 09:09 · LAX 18:09 · JFK 21:09
    ♥ Do have faith in what you're doing.