Announcement Announcement Module
Collapse
No announcement yet.
Problem with ReloadableResourceBundleMessageSource Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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 :
    Code:
     <bean id="messageSource"
              class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
            <property name="basenames">
                <list>
                      <value>WEB-INF/content/SoftCuStrings</value>
                </list>
            </property>
            <property name="defaultEncoding" value="UTF-8"/>
        </bean>
    and SoftCuStrings is my *.properties file

    i have created a Listener :
    Code:
    public class CmiServletListener implements ServletContextListener {
    	@Override
    	public void contextInitialized(ServletContextEvent sce) {
    		ServerMessageResourceFactory serverMessageResourceFactory = (ServerMessageResourceFactory) WebApplicationContextUtils
    				.getWebApplicationContext(sce.getServletContext()).getBean("serverMessageResourceFactory");
    		SoftCuMessageTest.SERVER_GLOBAL_RES = serverMessageResourceFactory.getSoftCuStrings();
    	}
    
    	@Override
    	public void contextDestroyed(ServletContextEvent sce) {
    
    	}
    }
    which is defined in my web.xml :
    Code:
       <listener>
            <listener-class>com.francetelecom.softcu.app.impl.listener.CmiServletListener</listener-class>
       </listener>
    the bean in this code is define in my spring file :
    Code:
    <bean id="serverMessageResourceFactory" class="com.francetelecom.softcu.app.impl.listener.ServerMessageResourceFactory"/>
    and here is my serverMessageResourceFactory file :
    Code:
    public class ServerMessageResourceFactory {
    
    	InvocationHandler handler = new InvocationHandler() {
    		@Override
    		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...

    Comment

    Working...
    X