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

2021-03-17  本文已影响0人  Anson_1f2a

框架: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

上一篇下一篇

猜你喜欢

热点阅读