Saturday, February 09, 2013

java.lang.ClassCastException: CustomReloadableResourceBundleMessageSource cannot be cast to org.springframework.context.support.DelegatingMessageSource

I needed to hook into Spring to use my own MessageSource for internationalization. I declared my custom bean and when I tried to use the new functionality I got:
java.lang.ClassCastException:  com.sample.web.CustomReloadableResourceBundleMessageSource cannot be cast to org.springframework.context.support.DelegatingMessageSource
This error happens when Spring cannot find the bean and instead initializes a default. If you inspect DEBUG traces you will see that clearly.

Hence this is a classloader issue which in my case was due to the fact that I was not declaring the bean in the application context xml but rather in the spring servlet xml. It took me some hours to realize what was really happening.

No comments:

Followers