Spring MVC ResourceBundleViewResolver Configuration Example

In previous examples, we learned about XmlViewResolver and InternalResourceViewResolver view templates. In this post, we will learn about ResourceBundleViewResolver templates. ResourceBundleViewResolver loads view beans from a resource bundle in the classpath root. Note that ResourceBundleViewResolver can also take advantage of the resource bundle capability to load view beans from different resource bundles for different locales (this is not possible with other two view resolvers).

By default, ResourceBundleViewResolver loads view names from “views.properties” file present into classpath but this location can be overridden through the basename property.

<bean class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
    <property name="basename" value="views" />

In views.properties resource bundle, you can declare view beans in the format of properties and their declaration is equivalent to the XML bean declaration which we saw in XmlViewResolver example.

<!--beans xmlns="http://www.springframework.org/schema/beans"

    <bean id="home" class="org.springframework.web.servlet.view.JstlView">
        <property name="url" value="/WEB-INF/jsp/home.jsp" />

    <bean id="admin/home" class="org.springframework.web.servlet.view.JstlView">
        <property name="url" value="/WEB-INF/jsp/admin/home.jsp" />

    <bean id="logOffRedirect" class="org.springframework.web.servlet.view.RedirectView">
        <property name="url" value="home" />

//Equivalent resource bundle properites




With above configuration, when controller return a logical view name “home” then ResourceBundleViewResolver will find the key starting with “home” in views.properties file, and return the corresponding view’s URL i.e. “/WEB-INF/jsp/home.jsp” back to the DispatcherServlet.

Drop me your queries if something needs more explanation.

Happy Learning !!

Was this post helpful?

Join 7000+ Fellow Programmers

Subscribe to get new post notifications, industry updates, best practices, and much more. Directly into your inbox, for free.

1 thought on “Spring MVC ResourceBundleViewResolver Configuration Example”

Comments are closed.


A blog about Java and its related technologies, the best practices, algorithms, interview questions, scripting languages, and Python.