Spring MVC - ResourceBundleViewResolver Configuration
Last Updated :
24 Apr, 2025
ResourceBundleViewResolver in Spring MVC is used to resolve "view named" by view beans in the ".properties" file. View beans defined in the properties file are utilized by the ResourceBundleViewResolver to determine the view names. Using the Spring Web MVC Framework, the ResourceBundleViewResolver may be utilized as demonstrated in the following example.
ResourceBundleViewResolver Configuration in Spring MVC
ResourceBundleViewResolver is a ViewResolver that uses a ResourceBundle property file for bean definitions. It is built with a bean and a base property file name set using setBasename(). This function performs internationalization and generates key-value pair values for view classes like JstlView and RedirectView. The default file name is viewed, but the base name can be changed using setBasename().
Resource Bundle Property File
Locate the property file. In this case, the data for two returned controller method values are being configured.
result.(class)=org.springframework.web.servlet.view.JstlView
result.url=/views/success.jsp
refer.(class)=org.springframework.web.servlet.view.RedirectView
refer.url=http://geeksforgeeks.org
Java Config for ResourceBundleViewResolver Bean
To define the ResourceBundleViewResolver bean, locate the Java configuration file:
Java
package org.geeksforgeeks.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.ResourceBundleViewResolver;
@Configuration
@ComponentScan("org.geeksforgeeks")
public class ResolverConfig {
@Bean //bean configuration
public ResourceBundleViewResolver resourceBundleViewResolver() {
ResourceBundleViewResolver resolver = new ResourceBundleViewResolver(); //object creation
resolver.setBasename("spring-mvc-views");
return resolver;
}
}