美文网首页
使用非context path方式在接口前加路径

使用非context path方式在接口前加路径

作者: Anson_1f2a | 来源:发表于2021-03-17 11:29 被阅读0次

    框架:spring webflux
    目标:不使用context path方式,在全部请求接口前加自定义路径
    方案:编写配置类

    import org.springframework.context.annotation.Configuration
    import org.springframework.web.bind.annotation.RestController
    import org.springframework.web.reactive.config.PathMatchConfigurer
    import org.springframework.web.reactive.config.WebFluxConfigurer
    
    /**
     * @Author  Anson
     * @Date  2021/3/12 12:12
     * @Version 1.0
     */
    @Configuration
    class WebConfig : WebFluxConfigurer {
    
        override fun configurePathMatching(configurer: PathMatchConfigurer) {
            configurer.addPathPrefix("/apis") { c -> c.isAnnotationPresent(RestController::class.java) }
        }
    }
    

    解释:判断凡是使用了RestController注解定义的接口前都加上/apis路径
    PS:使用spring-web的话,则继承WebMvcConfigurer

    相关文章

      网友评论

          本文标题:使用非context path方式在接口前加路径

          本文链接:https://www.haomeiwen.com/subject/mliscltx.html