高级 Java 配置

@EnableWebMvc 导入 DelegatingWebMvcConfiguration,它

  • 为 Spring MVC 应用程序提供默认的 Spring 配置

  • 检测并委托给 WebMvcConfigurer 实现来定制该配置。

对于高级模式,您可以删除 @EnableWebMvc 并直接从 DelegatingWebMvcConfiguration 扩展,而不是实现 WebMvcConfigurer,如以下示例所示

  • Java

  • Kotlin

@Configuration
public class WebConfiguration extends DelegatingWebMvcConfiguration {

	// ...
}
@Configuration
class WebConfiguration : DelegatingWebMvcConfiguration() {

	// ...
}

您可以保留 WebConfig 中的现有方法,但现在您还可以覆盖基类中的 bean 声明,并且您的类路径上仍然可以有任意数量的其他 WebMvcConfigurer 实现。

© . This site is unofficial and not affiliated with VMware.