Announcement Announcement Module
No announcement yet.
Problem with ReloadableResourceBundleMessageSource Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with ReloadableResourceBundleMessageSource

    Hi everyone !

    i have a problem using the class ReloadableResourceBundleMessageSource...
    i'll explain my problem. I want to use Messages on server Side, and i' trying to use ReloadableResourceBundleMessageSource.

    i have define this in my Spring file :
     <bean id="messageSource"
            <property name="basenames">
            <property name="defaultEncoding" value="UTF-8"/>
    and SoftCuStrings is my *.properties file

    i have created a Listener :
    public class CmiServletListener implements ServletContextListener {
    	public void contextInitialized(ServletContextEvent sce) {
    		ServerMessageResourceFactory serverMessageResourceFactory = (ServerMessageResourceFactory) WebApplicationContextUtils
    		SoftCuMessageTest.SERVER_GLOBAL_RES = serverMessageResourceFactory.getSoftCuStrings();
    	public void contextDestroyed(ServletContextEvent sce) {
    which is defined in my web.xml :
    the bean in this code is define in my spring file :
    <bean id="serverMessageResourceFactory" class=""/>
    and here is my serverMessageResourceFactory file :
    public class ServerMessageResourceFactory {
    	InvocationHandler handler = new InvocationHandler() {
    		public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    			return messageSource.getMessage(method.getAnnotation(LocalizableResource.Key.class).value(), args, null);
    	private ReloadableResourceBundleMessageSource messageSource;
    	public SoftCuStrings getSoftCuStrings() {
    		return (SoftCuStrings) Proxy.newProxyInstance(SoftCuStrings.class.getClassLoader(), new Class[] { SoftCuStrings.class }, handler);
    	public void setMessageResource(ReloadableResourceBundleMessageSource messageSource) {
    		this.messageSource = messageSource;
    to be quick, when i'm using my serverMessageResourceFactory, my messageResource is null...
    i thought that my classpath is wrong, but, i don't think so...
    someone can help me ? beacause i'm completely stuck :/

    thx !!

  • #2
    to be quick, when i'm using my serverMessageResourceFactory, my messageResource is null...
    And why should it be injected?! You no where specify it to be injected. There is no annotation on the field nor do you define the property in your xml file. So how on earth should spring know you want that injected?

    Also your code is flawed use the MessageSource interface instead of the concrete implementation to program against! I would suggest you let your ServerMessageResourceFactory implement MessageSourceAware...