框架: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
类
网友评论