{"id":121202,"date":"2023-11-12T16:29:12","date_gmt":"2023-11-12T14:29:12","guid":{"rendered":"https:\/\/examples.javacodegeeks.com\/?p=121202"},"modified":"2023-11-12T16:29:14","modified_gmt":"2023-11-12T14:29:14","slug":"spring-webmvcconfigurer-customize-default-mvc-configurations","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/","title":{"rendered":"Spring WebMvcConfigurer: Customize Default MVC Configurations"},"content":{"rendered":"<p><strong>Spring WebMvcConfigurer<\/strong> allows developers to customize default MVC configurations in Spring applications. By implementing this interface, users can tailor various aspects of the MVC framework, such as adding interceptors, resource handling, and view controllers. This flexibility enables fine-grained control over the web application&#8217;s behavior, making it adaptable to specific project requirements. Whether configuring path matching or setting up custom converters, the WebMvcConfigurer interface empowers developers to seamlessly extend and modify the default settings, fostering a more tailored and efficient web development experience within the Spring framework.<\/p>\n<h2><a name=\"introduction\"><\/a>1. Introduction to Spring WebMvcConfigurer<\/h2>\n<p><a href=\"https:\/\/docs.spring.io\/spring-framework\/docs\/current\/javadoc-api\/org\/springframework\/web\/servlet\/config\/annotation\/WebMvcConfigurer.html\" target=\"_blank\" rel=\"noopener\">Spring WebMvcConfigurer<\/a> is an interface in the Spring Framework that provides a powerful mechanism for developers to customize and extend the default configurations of the Spring MVC (Model-View-Controller) framework. This interface plays a crucial role in enabling fine-grained control over various aspects of the MVC infrastructure, allowing developers to tailor their web applications to specific needs.<\/p>\n<p>The <code>WebMvcConfigurer<\/code> interface is designed to be implemented by developers who want to customize the configuration of the Spring MVC framework in their applications.<\/p>\n<h2>2. Default MVC Configurations in Spring<\/h2>\n<p>In the Spring Framework, the Model-View-Controller (MVC) architecture provides a robust structure for building web applications. Spring MVC comes with default configurations that streamline the development process, allowing developers to focus on business logic rather than complex setups. Let&#8217;s explore some of the key default configurations and how they contribute to the efficiency of Spring MVC.<\/p>\n<ul>\n<li>DispatcherServlet: At the core of Spring MVC is the <code>DispatcherServlet<\/code>. It acts as a front controller, receiving all incoming requests and dispatching them to the appropriate controllers. By default, the <code>DispatcherServlet<\/code> is configured in the <code>web.xml<\/code> file, making it the entry point for handling HTTP requests.<\/li>\n<li>Request Mapping: Spring MVC employs sensible default conventions for mapping requests to controllers. Methods in controllers are annotated with <code>@RequestMapping<\/code>, and by default, they match URLs based on their method names. This convention minimizes the need for explicit configuration, promoting a convention-over-configuration approach.<\/li>\n<li>View Resolution: Default view resolution in Spring MVC is designed to be flexible. It uses a combination of convention and configuration to locate the appropriate view templates. The <code>ViewResolver<\/code> interface allows developers to customize view resolution strategies if needed.<\/li>\n<li>Model Binding: Spring MVC automatically binds request parameters to method parameters, simplifying the handling of form submissions. This feature eliminates the need for manual parsing and conversion of request data, enhancing developer productivity.<\/li>\n<li>Exception Handling: Spring MVC provides default mechanisms for handling exceptions during request processing. The <code>ExceptionHandler<\/code> annotation allows developers to define methods to handle specific exception types gracefully, contributing to a more robust error-handling strategy.<\/li>\n<\/ul>\n<h2>3. Configure View Resolvers<\/h2>\n<p>View resolvers play a crucial role in a Spring MVC application by determining how view names are translated into actual views. Spring provides a flexible and extensible mechanism for configuring view resolution. In Spring MVC, a view resolver is responsible for translating logical view names returned by controllers into actual view objects. The view resolver operates in conjunction with the <code>View<\/code> interface, which represents the rendering of the response.<\/p>\n<p>The <code>InternalResourceViewResolver<\/code> is a commonly used view resolver in Spring. It resolves logical view names to JSP pages or other resources within the application context. Here&#8217;s an example configuration in a Spring XML context file:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Code Snippet #1<\/em><\/span><\/p>\n<pre class=\"brush:xml; wrap-lines:false;\">&lt;bean class=\"org.springframework.web.servlet.view.InternalResourceViewResolver\"&gt;\n&lt;property name=\"prefix\" value=\"\/WEB-INF\/views\/\" \/&gt;\n&lt;property name=\"suffix\" value=\".jsp\" \/&gt;\n&lt;\/bean&gt;\n<\/pre>\n<p>For applications using Thymeleaf as the template engine, the <code>ThymeleafViewResolver<\/code> can be configured. It resolves logical view names to Thymeleaf templates. Here&#8217;s an example JavaConfig setup:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Code Snippet #2<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false;\">@Configuration\npublic class ThymeleafConfig {\n\n@Bean\npublic ViewResolver thymeleafViewResolver(SpringTemplateEngine templateEngine) {\nThymeleafViewResolver resolver = new ThymeleafViewResolver();\nresolver.setTemplateEngine(templateEngine);\nresolver.setCharacterEncoding(\"UTF-8\");\nreturn resolver;\n}\n\n\/\/ Other Thymeleaf configuration\n}\n<\/pre>\n<p>Developers can create custom view resolvers by implementing the <code>ViewResolver<\/code> interface. This allows for highly specialized view resolution strategies tailored to specific project requirements.<\/p>\n<h2>4. Configure View Mappings<\/h2>\n<p>View mappings in Spring MVC allow developers to define how logical view names are mapped to actual view implementations. This configuration is crucial for shaping the way views are resolved and rendered in response to client requests. View mappings define the relationship between logical view names returned by controllers and the corresponding view implementations. Spring MVC provides a flexible mechanism for configuring these mappings, allowing developers to choose the most suitable strategy for their applications.<\/p>\n<p>The <code>InternalResourceViewResolver<\/code> is a commonly used view resolver in Spring that also plays a role in view mappings. It resolves logical view names to JSP pages or other resources within the application context. Below is an example configuration:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Code Snippet #1<\/em><\/span><\/p>\n<pre class=\"brush:xml; wrap-lines:false;\">&lt;bean class=\"org.springframework.web.servlet.view.InternalResourceViewResolver\"&gt;\n&lt;property name=\"prefix\" value=\"\/WEB-INF\/views\/\" \/&gt;\n&lt;property name=\"suffix\" value=\".jsp\" \/&gt;\n&lt;\/bean&gt;\n<\/pre>\n<p>Spring MVC allows developers to define view mappings using view controllers. This is particularly useful for simple mappings where no business logic is involved. Below is an example JavaConfig setup:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline;\"><em>Code Snippet #2<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false;\">@Configuration\npublic class WebConfig implements WebMvcConfigurer {\n\n@Override\npublic void addViewControllers(ViewControllerRegistry registry) {\nregistry.addViewController(\"\/home\").setViewName(\"home\");\nregistry.addViewController(\"\/about\").setViewName(\"about\");\n\/\/ Add more view mappings as needed\n}\n}\n<\/pre>\n<p>Developers can create custom view resolvers to implement highly specialized view mapping strategies. This involves implementing the <code>ViewResolver<\/code> interface and providing a custom implementation for resolving logical view names to actual views.<\/p>\n<h2>5. Configure Static Resource Handling<\/h2>\n<p>Static resources, such as stylesheets, images, and JavaScript files, are an integral part of web applications. Configuring how these resources are handled in a Spring application is essential for ensuring efficient delivery to clients. Spring MVC uses default locations to look for static resources within the application. By default, resources placed in the <code>\/static<\/code>, <code>\/public<\/code>, <code>\/resources<\/code>, or <code>\/META-INF\/resources<\/code> directories are automatically mapped to the root of the web application. Developers can customize these locations based on project requirements.<\/p>\n<p>In XML-based configuration, the <code>mvc:resources<\/code> element can be used to configure static resource handling. Below is an example configuration in a Spring XML context file:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Code Snippet #1<\/em><\/span><\/p>\n<pre class=\"brush:xml; wrap-lines:false;\">&lt;mvc:resources mapping=\"\/resources\/**\" location=\"\/static\/\" \/&gt;\n<\/pre>\n<p>For JavaConfig-based configurations, developers can extend the <code>WebMvcConfigurerAdapter<\/code> class and override the <code>addResourceHandlers<\/code> method. Here&#8217;s an example:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Code Snippet #2<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false;\">@Configuration\npublic class WebConfig extends WebMvcConfigurerAdapter {\n\n@Override\npublic void addResourceHandlers(ResourceHandlerRegistry registry) {\nregistry.addResourceHandler(\"\/resources\/**\").addResourceLocations(\"\/static\/\");\n}\n}\n<\/pre>\n<p>Spring allows developers to configure a resource chain for static resources. This includes settings for cache control, version strategy, and custom resource transformations. Below is an example JavaConfig setup:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Code Snippet #3<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false;\">@Configuration\npublic class WebConfig implements WebMvcConfigurer {\n\n@Override\npublic void addResourceHandlers(ResourceHandlerRegistry registry) {\nregistry.addResourceHandler(\"\/resources\/**\")\n\t\t.addResourceLocations(\"\/static\/\")\n\t\t.setCacheControl(CacheControl.maxAge(1, TimeUnit.DAYS).cachePublic());\n}\n}\n<\/pre>\n<h2>6. Configure Interceptors<\/h2>\n<p>Interceptors in Spring MVC provide a powerful mechanism to perform pre-processing and post-processing of web requests. They allow developers to inject custom logic before a request is handled by a controller or after the response is generated. Interceptors are components in the Spring MVC framework that allow developers to intercept and modify the processing of a web request. They can be used for tasks such as logging, authentication, authorization, and more. Interceptors are executed in a specific order defined by their configuration.<\/p>\n<p>To create a custom interceptor, developers need to implement the <code>HandlerInterceptor<\/code> interface. This interface defines three methods: <code>preHandle<\/code>, <code>postHandle<\/code>, and <code>afterCompletion<\/code>. Below is an example of a simple logging interceptor:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Code Snippet #1<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false;\">public class LoggingInterceptor implements HandlerInterceptor {\n\n@Override\npublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {\nSystem.out.println(\"Request received for: \" + request.getRequestURI());\nreturn true;\n}\n\n\/\/ Implement postHandle and afterCompletion as needed\n}\n<\/pre>\n<p>Interceptors can be configured in the Spring application context. In XML-based configurations, the <code>mvc:interceptors<\/code> element is used. In JavaConfig, developers can override the <code>addInterceptors<\/code> method in a class that implements <code>WebMvcConfigurer<\/code>. Below is an example JavaConfig setup:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Code Snippet #2<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false;\">@Configuration\npublic class WebConfig implements WebMvcConfigurer {\n\n@Override\npublic void addInterceptors(InterceptorRegistry registry) {\nregistry.addInterceptor(new LoggingInterceptor());\n\/\/ Add more interceptors as needed\n}\n}\n<\/pre>\n<p>Interceptors are executed in the order they are added to the registry. The order can be explicitly set when adding interceptors. By default, interceptors have an order value of <code>Ordered.LOWEST_PRECEDENCE<\/code>, meaning they are executed last.<\/p>\n<h2>7. Configure Default Content Negotiation<\/h2>\n<p>Content negotiation in Spring MVC allows developers to serve different representations of a resource based on client preferences. It involves selecting the appropriate media type (JSON, XML, HTML, etc.) for a response. Content negotiation is the process of selecting the most suitable representation of a resource based on the client&#8217;s requested media types. Spring MVC uses the <code>ContentNegotiationConfigurer<\/code> class to configure how this negotiation should take place. By default, Spring MVC uses the <code>Accept<\/code> header in the HTTP request to determine the client&#8217;s media type preference. If the client doesn&#8217;t specify a preference, the server may use a default media type, such as JSON or XML, depending on the configuration.<\/p>\n<p>To customize content negotiation, developers can create a configuration class that extends <code>WebMvcConfigurerAdapter<\/code> (or implements <code>WebMvcConfigurer<\/code> in recent versions of Spring). Here&#8217;s an example JavaConfig setup:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Code Snippet #1<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false;\">@Configuration\npublic class WebConfig extends WebMvcConfigurerAdapter {\n\n@Override\npublic void configureContentNegotiation(ContentNegotiationConfigurer configurer) {\nconfigurer\n.defaultContentType(MediaType.APPLICATION_JSON)\n.mediaType(\"json\", MediaType.APPLICATION_JSON)\n.mediaType(\"xml\", MediaType.APPLICATION_XML);\n}\n}\n<\/pre>\n<p>Another way to perform content negotiation is by using URL extensions. For example, appending <code>.json<\/code> or <code>.xml<\/code> to the request URL can indicate the desired media type. This can be configured as follows:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Code Snippet #2<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false;\">@Configuration\npublic class WebConfig extends WebMvcConfigurerAdapter {\n\n@Override\npublic void configureContentNegotiation(ContentNegotiationConfigurer configurer) {\nconfigurer\n.favorPathExtension(true)\n.mediaType(\"json\", MediaType.APPLICATION_JSON)\n.mediaType(\"xml\", MediaType.APPLICATION_XML);\n}\n}\n<\/pre>\n<h2>8. Configure Message Converters<\/h2>\n<p>Message converters in Spring are essential components for handling the conversion of HTTP request and response bodies. They play a crucial role in supporting various data formats, such as JSON, XML, or custom formats, enabling seamless communication between clients and servers. Message converters are responsible for translating Java objects into a format that can be sent over the network in an HTTP request or response. In Spring, these converters are part of the framework&#8217;s <code>HttpMessageConverter<\/code> interface and can be configured to support different data formats.<\/p>\n<p>Spring MVC comes with a set of default message converters that support common data formats. These include converters for JSON, XML, form data, and more. By default, Spring configures these converters to handle the most common scenarios automatically.<\/p>\n<p>To customize or add additional message converters, developers can create a configuration class that extends <code>WebMvcConfigurerAdapter<\/code> (or implements <code>WebMvcConfigurer<\/code> in recent versions of Spring). Below is an example JavaConfig setup:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Code Snippet #1<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false;\">@Configuration\npublic class WebConfig extends WebMvcConfigurerAdapter {\n\n@Override\npublic void configureMessageConverters(List&lt;HttpMessageConverter&gt; converters) {\n\/\/ Add custom converters or modify existing ones\nconverters.add(new MyCustomMessageConverter());\n}\n}\n<\/pre>\n<p>The order of message converters is significant. When a request is processed, Spring iterates through the list of converters, and the first one that supports the requested media type is used. Developers can set the order explicitly or rely on the default ordering.<\/p>\n<p>Creating a custom message converter involves implementing the <code>HttpMessageConverter<\/code> interface. This interface defines methods for reading and writing messages. Below is a simplified example:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Code Snippet #2<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false;\">public class MyCustomMessageConverter implements HttpMessageConverter&lt;MyObject&gt; {\n\n\/\/ Implement methods for reading and writing MyObject\n}\n<\/pre>\n<h2>9. Configure CORS<\/h2>\n<p>Cross-Origin Resource Sharing (CORS) is a security feature implemented by web browsers that restricts webpages from making requests to a different domain than the one that served the original webpage. In a Spring application, configuring CORS is crucial when building web services that need to be accessed from different origins. CORS is a security feature implemented by web browsers to prevent unauthorized web pages from making requests to a domain other than the one that served the original web page. It is enforced by the browser and involves the exchange of specific HTTP headers between the client and the server. By default, Spring Security includes some basic CORS support, allowing simple cross-origin requests. However, for more advanced configurations or specific requirements, developers may need to customize the CORS configuration.<\/p>\n<p>To customize CORS configuration in a Spring application, developers can create a configuration class that extends <code>WebMvcConfigurerAdapter<\/code> (or implements <code>WebMvcConfigurer<\/code> in recent versions of Spring). Below is an example JavaConfig setup:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Code Snippet #1<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false;\">@Configuration\npublic class WebConfig extends WebMvcConfigurerAdapter {\n\n@Override\npublic void addCorsMappings(CorsRegistry registry) {\nregistry.addMapping(\"\/api\/**\")\n\t.allowedOrigins(\"https:\/\/example.com\")\n\t.allowedMethods(\"GET\", \"POST\", \"PUT\", \"DELETE\")\n\t.allowedHeaders(\"Authorization\")\n\t.exposedHeaders(\"Authorization\")\n\t.allowCredentials(true)\n\t.maxAge(3600);\n}\n}\n<\/pre>\n<p>To configure CORS globally for all controllers, developers can use the <code>@CrossOrigin<\/code> annotation at the controller level or use the <code>CorsRegistry<\/code> within a <code>WebMvcConfigurer<\/code> implementation.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Code Snippet #2<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false;\">@RestController\n@CrossOrigin(origins = \"https:\/\/example.com\")\npublic class MyController {\n\/\/ Controller methods\n}\n<\/pre>\n<h2>10. Configure Argument Resolvers<\/h2>\n<p>Argument resolvers in Spring MVC provide a way to customize how method parameters are resolved before a controller method is invoked. They allow developers to inject custom logic for resolving method arguments, such as extracting values from request attributes, headers, or other sources. Argument resolvers in Spring MVC are responsible for resolving method parameters before invoking a controller method. They convert raw HTTP request data into method parameters, allowing developers to work with higher-level abstractions in their controllers. Spring MVC comes with a set of default argument resolvers that handle common scenarios, such as resolving parameters from path variables, request parameters, request headers, and more. These default resolvers are automatically applied based on the method parameter types and annotations.<\/p>\n<p>To customize or add additional argument resolvers, developers can create a configuration class that extends <code>WebMvcConfigurerAdapter<\/code> (or implements <code>WebMvcConfigurer<\/code> in recent versions of Spring). Below is an example JavaConfig setup:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Code Snippet #1<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false;\">@Configuration\npublic class WebConfig extends WebMvcConfigurerAdapter {\n\n@Override\npublic void addArgumentResolvers(List argumentResolvers) {\nargumentResolvers.add(new CustomArgumentResolver());\n\/\/ Add more custom resolvers as needed\n}\n}\n<\/pre>\n<p>Creating a custom argument resolver involves implementing the <code>HandlerMethodArgumentResolver<\/code> interface. This interface defines methods for checking if it supports a given parameter type and for resolving the actual argument. Below is a simplified example:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Code Snippet #2<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false;\">public class CustomArgumentResolver implements HandlerMethodArgumentResolver {\n\n@Override\npublic boolean supportsParameter(MethodParameter parameter) {\nreturn parameter.getParameterType() == MyCustomObject.class;\n}\n\n@Override\npublic Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,\n\t\t\t\t  NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {\n\/\/ Custom logic to resolve the argument\nreturn new MyCustomObject();\n}\n}\n<\/pre>\n<p>The order of argument resolvers is significant. When a controller method is invoked, Spring iterates through the list of resolvers, and the first one that supports the parameter type is used. Developers can set the order explicitly or rely on the default ordering.<\/p>\n<h2>11. Conclusion<\/h2>\n<p>In conclusion, the configuration of various aspects in a Spring MVC application is crucial for building robust and flexible web solutions. Understanding and customizing default MVC configurations lay the foundation for tailoring the behavior of the application to specific requirements.<\/p>\n<p>Configuring view resolvers and mappings empowers developers to control how logical view names are translated into concrete view implementations, enhancing the flexibility of view rendering. Meanwhile, efficient static resource handling ensures seamless integration of stylesheets, images, and JavaScript files, contributing to an optimized user experience.<\/p>\n<p>Integrating interceptors allows for the injection of custom logic during the request-processing lifecycle, providing avenues for tasks such as logging, authentication, and authorization. Default content negotiation configuration and message converters are essential for facilitating seamless communication between clients and servers, supporting various data formats based on client preferences.<\/p>\n<p>Cross-Origin Resource Sharing (CORS) configuration becomes paramount when developing web services accessed from different origins, ensuring secure communication. Lastly, configuring argument resolvers empowers developers to customize how method parameters are resolved in controller methods, offering flexibility in handling different types of inputs.<\/p>\n<p>Collectively, these configuration aspects showcase the versatility and extensibility of the Spring MVC framework.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spring WebMvcConfigurer allows developers to customize default MVC configurations in Spring applications. By implementing this interface, users can tailor various aspects of the MVC framework, such as adding interceptors, resource handling, and view controllers. This flexibility enables fine-grained control over the web application&#8217;s behavior, making it adaptable to specific project requirements. Whether configuring path matching &hellip;<\/p>\n","protected":false},"author":119,"featured_media":1248,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52],"tags":[46675,1054,1213],"class_list":["post-121202","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring","tag-springboot","tag-spring","tag-spring-mvc"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Spring WebMvcConfigurer: Customize Default MVC Configurations - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Spring WebMvcConfigurer: Optimize Spring MVC with WebMvcConfigurer for tailored web application configurations.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring WebMvcConfigurer: Customize Default MVC Configurations - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Spring WebMvcConfigurer: Optimize Spring MVC with WebMvcConfigurer for tailored web application configurations.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-12T14:29:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-12T14:29:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Yatin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Yatin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/\"},\"author\":{\"name\":\"Yatin\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13\"},\"headline\":\"Spring WebMvcConfigurer: Customize Default MVC Configurations\",\"datePublished\":\"2023-11-12T14:29:12+00:00\",\"dateModified\":\"2023-11-12T14:29:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/\"},\"wordCount\":2106,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"keywords\":[\"#springboot\",\"spring\",\"Spring MVC\"],\"articleSection\":[\"spring\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/\",\"name\":\"Spring WebMvcConfigurer: Customize Default MVC Configurations - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"datePublished\":\"2023-11-12T14:29:12+00:00\",\"dateModified\":\"2023-11-12T14:29:14+00:00\",\"description\":\"Spring WebMvcConfigurer: Optimize Spring MVC with WebMvcConfigurer for tailored web application configurations.\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"spring\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/spring\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Spring WebMvcConfigurer: Customize Default MVC Configurations\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13\",\"name\":\"Yatin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg\",\"caption\":\"Yatin\"},\"description\":\"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).\",\"sameAs\":[\"https:\/\/www.javacodegeeks.com\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/yatin-batra\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring WebMvcConfigurer: Customize Default MVC Configurations - Java Code Geeks","description":"Spring WebMvcConfigurer: Optimize Spring MVC with WebMvcConfigurer for tailored web application configurations.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/","og_locale":"en_US","og_type":"article","og_title":"Spring WebMvcConfigurer: Customize Default MVC Configurations - Java Code Geeks","og_description":"Spring WebMvcConfigurer: Optimize Spring MVC with WebMvcConfigurer for tailored web application configurations.","og_url":"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2023-11-12T14:29:12+00:00","article_modified_time":"2023-11-12T14:29:14+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Yatin","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Yatin","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/"},"author":{"name":"Yatin","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13"},"headline":"Spring WebMvcConfigurer: Customize Default MVC Configurations","datePublished":"2023-11-12T14:29:12+00:00","dateModified":"2023-11-12T14:29:14+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/"},"wordCount":2106,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","keywords":["#springboot","spring","Spring MVC"],"articleSection":["spring"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/","url":"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/","name":"Spring WebMvcConfigurer: Customize Default MVC Configurations - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","datePublished":"2023-11-12T14:29:12+00:00","dateModified":"2023-11-12T14:29:14+00:00","description":"Spring WebMvcConfigurer: Optimize Spring MVC with WebMvcConfigurer for tailored web application configurations.","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/spring-webmvcconfigurer-customize-default-mvc-configurations\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/"},{"@type":"ListItem","position":4,"name":"spring","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/spring\/"},{"@type":"ListItem","position":5,"name":"Spring WebMvcConfigurer: Customize Default MVC Configurations"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13","name":"Yatin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg","caption":"Yatin"},"description":"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/examples.javacodegeeks.com\/author\/yatin-batra\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/121202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/119"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=121202"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/121202\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1248"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=121202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=121202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=121202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}