Filter Registrations
在设置 MockMvc
实例时,你可以注册一个或多个 Servlet Filter
实例,如下例所示:
When setting up a MockMvc
instance, you can register one or more Servlet Filter
instances, as the following example shows:
-
Java
-
Kotlin
mockMvc = standaloneSetup(new PersonController()).addFilters(new CharacterEncodingFilter()).build();
// Not possible in Kotlin until {kotlin-issues}/KT-22208 is fixed
已注册的过滤器通过 spring-test
中的 MockFilterChain
调用,并且最后一个过滤器委托给 DispatcherServlet
。
Registered filters are invoked through the MockFilterChain
from spring-test
, and the
last filter delegates to the DispatcherServlet
.