Deprecate mvc XML configuration namespace

This commit deprecates the `<mvc:*` XML configuration namespace for
configuring Spring MVC applications. This configuration model is lagging
behind in the 6.x generation already and we don't intend to invest in
this space to close that gap.

As of 7.0, using this XML namespace will result in a WARN log message.
This commit also states our intent in the reference documentation.

Closes gh-34063
This commit is contained in:
Brian Clozel
2024-12-17 11:55:08 +01:00
parent f094c46172
commit 4fd368b1af
2 changed files with 11 additions and 1 deletions

View File

@@ -7,6 +7,10 @@ You can use the `@EnableWebMvc` annotation to enable MVC configuration with prog
include-code::./WebConfiguration[tag=snippet,indent=0]
WARNING: As of 7.0, support for the XML configuration namespace for Spring MVC has been deprecated.
There are no plans yet for removing it completely but XML configuration will not be updated to follow
the Java configuration model.
NOTE: When using Spring Boot, you may want to use `@Configuration` classes of type `WebMvcConfigurer` but without `@EnableWebMvc` to keep Spring Boot MVC customizations. See more details in xref:web/webmvc/mvc-config/customize.adoc[the MVC Config API section] and in {spring-boot-docs-ref}/web/servlet.html#web.servlet.spring-mvc.auto-configuration[the dedicated Spring Boot documentation].
The preceding example registers a number of Spring MVC

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,9 @@
package org.springframework.web.servlet.config;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.xml.NamespaceHandler;
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
@@ -29,8 +32,11 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
*/
public class MvcNamespaceHandler extends NamespaceHandlerSupport {
private static final Log logger = LogFactory.getLog(MvcNamespaceHandler.class);
@Override
public void init() {
logger.warn("The XML configuration namespace for Spring MVC is deprecated, please use Java configuration instead.");
registerBeanDefinitionParser("annotation-driven", new AnnotationDrivenBeanDefinitionParser());
registerBeanDefinitionParser("default-servlet-handler", new DefaultServletHandlerBeanDefinitionParser());
registerBeanDefinitionParser("interceptors", new InterceptorsBeanDefinitionParser());