UTF-8 encoding and Spring message sources

This post http://www.cakesolutions.net/teamblogs/2009/04/02/utf-8-encoding-and-message-sources/ explains how you can get Spring to load message resource bundles for UTF-8 encoded characters. Always save you messages file as UTF-8. In Eclipse you can do that by going to the file properties and selecting UTF-8 in the text file encoding section.


Handler Interceptors For Annotation Based Configuration in Spring

Here’s what you need to have in your *-servlet.xml file:

<context:annotation-config />
<context:component-scan base-package="com.travelfusion.tfweb.guide.controller" />

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
   <property name="interceptors">
      <ref bean="myInterceptor" />

<bean id="myInterceptor" class="com.company.MyInterceptor">
  <property name="openingTime"><value>9</value></property>
  <property name="closingTime"><value>18</value></property>

And your interceptor class something like:

public class MyInterceptor implements HandlerInterceptor {
   private int openingTime;
   private int closingTime;

   public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3) throws    Exception {
      // TODO Auto-generated method stub

   public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3) throws    Exception {
      // TODO Auto-generated method stub

   public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
        Calendar cal = Calendar.getInstance();
        int hour = cal.get(HOUR_OF_DAY);
        if (openingTime <= hour < closingTime) {
           return true;
        } else {
           return false;