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 !!


Notify of
1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.

Our Blogs

REST API Tutorial

Dark Mode

Dark Mode