|
对于最新的稳定版本,请使用 Spring Framework 7.0.6! |
高级Java配置
@EnableWebMvc 引入了 DelegatingWebMvcConfiguration,这:
-
为Spring MVC应用程序提供默认的Spring配置
-
检测并委托给
WebMvcConfigurer实现以自定义该配置。
对于高级模式,你可以移除 @EnableWebMvc 并直接从 DelegatingWebMvcConfiguration 扩展,而不是实现 WebMvcConfigurer,
如下例所示:
-
Java
-
Kotlin
@Configuration
public class WebConfig extends DelegatingWebMvcConfiguration {
// ...
}
@Configuration
class WebConfig : DelegatingWebMvcConfiguration() {
// ...
}
你可以保留现有的方法在WebConfig中,但现在你也可以覆盖基类中的bean声明,并且你仍然可以在类路径上有任何数量的其他WebMvcConfigurer实现。