Since Spring 5.0, WebMvcConfigurer has Java 8 default methods. That means, for MVC configuration, we can implement this interface directly without extending WebMvcConfigurerAdapter (deprecated in 5.0).
Example
Implementing WebMvcConfigurer
package com.logicbig.example;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@EnableWebMvc
@Configuration
@ComponentScan
public class MyWebConfig implements WebMvcConfigurer {
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
registry.jsp("/WEB-INF/views/", ".jsp");
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
//this will map uri to jsp view directly without a controller
registry.addViewController("/hi")
.setViewName("hello");
}
}
src/main/webapp/WEB-INF/views/hello.jsp<%@ page language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<body>
Hello! <br/>
<%= new java.util.Date().toString() %>
</body>
</html>
Running App
To try examples, run embedded Jetty (configured in pom.xml of example project below):
mvn jetty:run
Curl Output $ curl -s http://localhost:8080/spring-mvc-configurer/hi
<html> <body> Hello! <br/> Tue Jun 23 17:36:40 CST 2026 </body> </html>
Example ProjectDependencies and Technologies Used: - spring-webmvc 7.0.6 (Spring Web MVC)
Version Compatibility: 3.2.9.RELEASE - 7.0.6 Version compatibilities of spring-webmvc with this example: Versions in green have been tested.
- jakarta.servlet-api 6.1.0 (Jakarta Servlet API documentation)
- jakarta.servlet.jsp.jstl 3.0.1 (Jakarta Standard Tag Library Implementation)
- JDK 25
- Maven 3.9.11
|