How to configure ResourceBundleViewResolver in Spring Framework 2.0

frameworks, java, spring

Solution

ResourceBundleViewResolver uses the key/vals in views.properties to create view beans (actually created in an internal application context). The name of the view bean in your example will be "logout" and it will be a bean of type JstlView. JstlView has an attribute called URL which will be set to "WEB-INF/jsp/logout.jsp". You can set any attribute on the view class in a similar way.

What you appear to be missing is your controller/handler layer. If you want /myapp/logout.htm to serve logout.jsp, you must map a Controller into /myapp/logout.htm and that Controller needs to return the view name "logout". The ResourceBundleViewResolver will then be consulted for a bean of that name, and return your instance of JstlView.

Problem

Everywhere I look always the same explanation pop ups. Configure the view resolver. ``` <bean id="viewMappings" class="org.springframework.web.servlet.view.ResourceBundleViewResolver"> <property name="basename" value="views" /> </bean> ``` And then put a file in the classpath named view.properties with some key-value pairs (don't mind the names). ``` logout.class=org.springframework.web.servlet.view.JstlView logout.url=WEB-INF/jsp/logout.jsp ``` What does `logout.class` and `logout.url` mean? How does `ResourceBundleViewResolver` uses the key-value pairs in the file? My goal is that when someone enters the URI `myserver/myapp/logout.htm` the file `logout.jsp` gets served.

Original source