我们的目标是配置我的webflux servlet容器,这样当API调用预定义的路径时,无论调用的是大写还是小写路径,都将返回一个响应。
/api/用户应该给出与/api/USERS相同的结果
这个功能路由定义和下面的WebFluxConfigurer似乎并没有解决这个问题。
@Configuration
class UserRoutes {
@Bean
fun userRouterFunction(
userHandler: userHandler
) = coRouter {
"/users".nest {
GET("/all", userHandler::getAllUser)
@Configuration
@EnableWebFlux
class WebConfig : WebFluxConfigurer {
override fun configurePathMatching(configurer: PathMatchConfigurer) {
configurer.setUseCaseSensitiveMatch(false)
}
}
有什么不对劲吗?
@Configuration
类不能为final
类。修改其访问修饰符为open
@Configuration
@EnableWebFlux
open class WebConfig : WebFluxConfigurer {
override fun configurePathMatching(configurer: PathMatchConfigurer) {
configurer.setUseCaseSensitiveMatch(false)
}
}
这工作。我刚测试过。